Attempting to run one of Dublin, OH's useful Assessment Notebooks.
Was already informed by the Error Text that gis.content.add() has been deprecated, and that I must use the Folder.add() class/method to add X item to an ArcGIS Online Folder that gets to be specified by me.
So I attempted to set the specified folder, but am admonished:
AttributeError: 'ContentManager' object has no attribute 'folders'
Despite the Documentation telling me otherwise:
https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#folder
# Usage Example: >>> from arcgis.gis import GIS, ItemProperties, ItemTypeEnum >>> gis = GIS(profile="your_organization_profile") >>> data_path = r"<path_to_zipped_shapefile>" >>> item_props = ItemProperties(title="new_shapefile_item", item_type=ItemTypeEnum.SHAPEFILE.value, tags="new_shp_item,from_api", snippet="Demo item added from Python API") >>> folders_obj = gis.content.folders >>> item_folder = folders_obj.get(folder="water_data") >>> add_job = item_folder.add(item_properties=item_props, file=data_path) >>> if not add_job.done(): >>> print("...job precessing...") >>> else: >>> new_shp_item = add_job.result() >>> new_flyr_item = new_shp_item.publish()
I did find this User on GitHub with the same issue, but their solution (upgrading ArcGIS Pro to 3.4) is not a viable option for me: ContentManager.folders does not work as documented · Issue #2268 · Esri/arcgis-python-api
I can barely follow the script I'm trying to triage as it is. I'm not a developer. But any offered solution would be appreciated --just know that I may not understand complexities beyond adding/substituting lines of python in the Notebook I'm following.
Hi @ODWC_GIS,
What version of the API are you using?
import arcgis
print(arcgis.__version__)
You do not need to use the Folders class add(), it is simply a deprecation warning, not a removal error. I am using version 2.4.0 and although the Folder class is available, I can still use the ContentManager add() method just fine, but with the deprecation warning.
Your gis.content.add() is still good to use to add content to your ArcGIS Online - you'll just get the deprecation warning that at version 3.0.0 it will be removed.
You are getting AttributeError: 'ContentManager' object has no attribute 'folders' because you are at an API version that doesn't have that functionality, my guess is 2.1.0.1 or 2.2.0.1 (or in or around).
I hope that helps.
All the best,
Glen