def upload_csv(request):
try:
csv_filename = request.GET.get("csv_filename","")
ARC_GIS_API_KEY = apps.get_app_config('arcgis_bridge').ARC_GIS_API_KEY
if csv_filename:
if ARC_GIS_API_KEY:
gis = GIS(api_key=ARC_GIS_API_KEY)
if gis:
dir_path = os.path.dirname(os.path.realpath(__file__))
print("dir_path :: ", dir_path)
data_path = os.path.join(dir_path, "..\input_data")
print("data_path :: ", data_path)
csv_path = os.path.join(data_path, csv_filename)
print("csv_path :: ", csv_path)
ports_df = pandas.read_csv(csv_path)
# print("ports_df :: ", ports_df)
ports_fc = gis.content.import_data(ports_df)
print("ports_fc :: ", ports_fc)
# ports_fc_dict = dict(ports_fc.properties)
ports_fc_dict = dict(ports_fc.layer)
# print("ports_fc_dict :: ", ports_fc_dict)
ports_json = json.dumps({"featureCollection": {"layers": [ports_fc_dict]}})
# print("ports_json :: ", ports_json)
csv_properties = {
'title': 'test file',
'description': 'attempting content upload from API',
'tags': 'arcgis, python, testing, csv, importing',
'text': ports_json,
'type': 'Feature Collection'
}
try:
contentManager = gis.content
print("contentManager :: ", contentManager)
csv_item = contentManager.add(csv_properties)
print("csv_item :: ", csv_item)
csv_item_publish = csv_item.publish()
print("csv_item_publish :: ", csv_item_publish)
except Exception as e:
print("csv_item ERROR :: ", str(e))
return JsonResponse({"error": True, "message":str(e)})
return JsonResponse({"error": False, "message":"CSV Uploaded Successfully.","csv_item_publish":csv_item_publish})
else:
return JsonResponse({"error": True, "message":"ARC GIS API CONNECTION COULD NOT BE OBTAINED.","csv_item_publish":{}})
else:
return JsonResponse({"error": True, "message":"ARC GIS API KEY IS MISSING.","csv_item_publish":{}})
else:
return JsonResponse({"error": True, "message":"CSV FILE NAME IS MISSING.","csv_item_publish":{}})
except Exception as e:
return JsonResponse({"error": True, "message":str(e), "csv_item_publish":''})
[21/Jul/2023 10:07:50] "GET /arcgis_bridge/uploadCSV?csv_filename=file1.CSV HTTP/1.1" 200 68
dir_path :: C:\Users\aksha\Projects\arc_gis\sree_app\arcgis_bridge
data_path :: C:\Users\aksha\Projects\arc_gis\sree_app\arcgis_bridge\..\input_data
csv_path :: C:\Users\aksha\Projects\arc_gis\sree_app\arcgis_bridge\..\input_data\file1.CSV
ports_fc :: <FeatureCollection>
contentManager :: <arcgis.gis.ContentManager object at 0x0000023BC9E03070>
csv_item ERROR :: 'NoneType' object is not subscriptable
It means that your return from the content.add(...) is None.
contentManager.add(csv_properties)
Something is not set correctly and it's not adding so when it gets to the print, it cant subscript None to str.