AnsweredAssumed Answered

Upload sd file to server with rest api

Question asked by fallingdog Champion on Dec 12, 2019
Latest reply on May 6, 2020 by fallingdog

I am trying to do the pattern outlined in this post: 


arcpy - Publishing service using service definition file (sd) through the ArcGIS REST API? - Geographic Information Syst… 

and the same post on geonet:… 


But I am stuck on step one upload sd file to the server with rest api.

Upload—ArcGIS REST API: Services Directory | ArcGIS for Developers 

action = 'uploads/upload'
url = "http://{}:{}/arcgis/admin".format(server, port)
requestURL = url + "/{}".format(action)
query_dict = {
    'file': r'C:\xx\xx\',
    "token": token,
    "f": "json"
query_string = urllib.urlencode(query_dict)
r = urllib.urlopen(requestURL, query_string)
j = json.loads(
print j

The json output is:

{u'status': u'error', u'code': 500, u'messages': [u'This operation must be a multipart request.']}


I have also tried with requests without any luck:


token = get_token('user', 'password', 'server', '6080', 60)
item = r'C:\xx\xx\'
files = {'file': item}
payload = {'f': 'json', 'token': token}
url = 'http://server:6080/arcgis/admin/uploads/upload'

resp =, files=files, data=payload,
                     verify=False# Use verify=False if you don't have a certificate to use
json_data = resp.json()

If I look at the resp object in the debugger I see:

content = {"status":"error","messages":["No file is associated with the upload request."],"code":500}

How can I get this working?