Help with the following issue (Error:500 Item does not have a file) would be greatly appreciated
I have written the following python script with the assistance of some sample code I found and with the aid of ArcGIS Online Rest help documentation. You will note I have used 2 alternative methods to upload the same locally stored CSV file onto my orginisation's ArcGIS Online site. Both methods return the status of "Success" specifically with a message such as "{"success" : true,"id" : "0ded368614754acd88d00084d5804a7d","folder" : null}"
The upload at first glance looks fine as on the ArcGIS Online site a new item appears added to 'My Contents' and is correctly named with properties correctly populated by the python code. However, when I try to open the CSV file ArcGIS Online returns the error - Error:500 'Item does not have a file'.
Can someone please take a look at the code and suggest what may be the cause of error? I tried to upload different files including some in KML file format and got the exact same error.
The code below has dummy user-name and password details added and currently assumes that the local file is stored "'E:\sample.csv"
import json, urllib, urllib2 import requests from json import JSONEncoder def gentoken(username, password, referer, expiration=60): #Re-usable function to get a token required for Admin changes referer = "http://www.arcgis.com/" query_dict = {'username': username, 'password': password, 'expiration': str(expiration), 'client': 'referer', 'referer': referer, 'f': 'json'} tokenUrl = "https://www.arcgis.com/sharing/rest/generateToken" tokenResponse = urllib.urlopen(tokenUrl, urllib.urlencode(query_dict)) token = json.loads(tokenResponse.read()) if "token" not in token: print token['messages'] import sys sys.exit() else: # Return the token to the function which called for it print str(token) return token['token']
def uploadCSVfile1(token, ThePlaceTOupload):
files = {'file': open('E:\sample.csv','rb'), 'type':'CSV', 'filename':'E:\sample.csv', 'title':'AA_Upload_CSV_File_Method_1', 'async': 'false', 'accessInformation' : 'Copyright:? 2014 Hydro Tasmania', 'spatialReference':'GDA 94', 'licenseInfo':'This work is licensed to Hydro Tasmania', 'description': 'CSV description', 'tags':'web, mapping, application', 'snippet' : 'This new snippet', 'typeKeywords': 'Static', 'f': 'json', 'token': token } r = requests.post(ThePlaceTOupload, files) print r.content print "Method 1 Returned Message"