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:
https://community.esri.com/message/882685-re-how-do-i-publish-a-service-using-a-service-definition-file-sd-through-the-a…
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:\xyz\xyz\xyz.sd',
"token": token,
"f": "json"
}
query_string = urllib.urlencode(query_dict)
r = urllib.urlopen(requestURL, query_string)
j = json.loads(r.read())
print jThe 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:\xyz\xyz\xyz.sd'
files = {'file': item}
payload = {'f': 'json', 'token': token}
url = 'http://server:6080/arcgis/admin/uploads/upload'
resp = requests.post(url, 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?