Using f-string in `item_properties`

158
1
Jump to solution
12-08-2021 10:22 AM
timatcambrio
New Contributor

I cannot seem to use f-string and/or string variable in `item_properties` when I want to publish an item (GeoJSON in this case).

Here is what I have:

 

region = "Gulf of Mexico"
gis = GIS(username=USERNAME, password=PASSWORD)

data_path = "/path/to/data.json"
title = f"Objects in {region}"
item_properties = {"type": "GeoJson",
"title": title,
"tags": "object detection"}
item = gis.content.add(item_properties=item_properties, data=data_path)
publishedCollection = item.publish(file_type='geojson')

 

The use of a string variable gives me a `KeyError: 'type'` when I attempt to publish the item.

The `KeyError` would go away, however, if I use the following `item_properties`:

 

item_properties = {"type": "GeoJson",
"title": "Objects in Gulf of Mexico",
"tags": "object detection"}

 

Is this a known issue? I would like to programmatically set the title; is there a way around the inability to use a string variable/f-string?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
timatcambrio
New Contributor

It turns out that it was not the f-string that was the issue. It appears there might be a character limit to the title of the Feature Layer that was causing the problem.

View solution in original post

1 Reply
timatcambrio
New Contributor

It turns out that it was not the f-string that was the issue. It appears there might be a character limit to the title of the Feature Layer that was causing the problem.