import arcpy import xml.dom.minidom as DOM import os workspace = 'C:/Temp/hosted publishing/' # Reference map document for CreateSDDraft function. mapDoc = arcpy.mapping.MapDocument(r'C:\Temp\betty4.mxd') # Create service and sddraft variables for CreateSDDraft function. sddraft = workspace + 'HostedMS.sddraft' service = 'FeatureService' arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'MY_HOSTED_SERVICES', summary="test", tags='test') con = 'My Hosted Services' sd = workspace + service + '.sd' doc = DOM.parse(sddraft) # Read the sddraft xml. doc = DOM.parse(sddraft) # Change service from map service to feature service typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: # Get the TypeName we want to disable. if typeName.firstChild.data == "MapServer": typeName.firstChild.data = "FeatureServer" #Turn off caching configProps = doc.getElementsByTagName('ConfigurationProperties')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "isCached": # turn on caching keyValue.nextSibling.firstChild.data = "false" #Turn on feature access capabilities configProps = doc.getElementsByTagName('Info')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "WebCapabilities": # turn on caching keyValue.nextSibling.firstChild.data = "Query,Create,Update,Delete,Uploads,Editing" outXml = workspace + 'HostedMSNew.sddraft' f = open(outXml, 'w') doc.writexml( f ) f.close() analysis = arcpy.mapping.AnalyzeForSD(outXml) #print analysis #arcpy.SignOutFromPortal_server() arcpy.SignInToPortal_server("username","password","http://www.arcgis.com/") arcpy.StageService_server(outXml, sd) arcpy.UploadServiceDefinition_server(sd, con)
Pretty sure this will enable attachments, it works for me. Update variables at the bottom. You can switch TRUE to FALSE to disable attachments.import json, urllib, urllib2 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'} query_string = urllib.urlencode(query_dict) 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 return token['token'] def enableAttachment(token, fsURL): query_dict = {'updateDefinition': "{'hasAttachments':true}", #false 'f': 'json', 'token': token} query_string = urllib.urlencode(query_dict) attachResponse = urllib.urlopen(fsURL, urllib.urlencode(query_dict)) msg = json.loads(attachResponse.read()) print msg return USERNAME = " ______ " PASSWORD = " ______ " REFFER = "http://www.arcgis.com" fsURL = "http://services1.arcgis.com/<ORGANIZATION IDENTFIER/arcgis/admin/services/<SERVICE NAME>.FeatureServer/0/updateDefinition" # for example, a link may look like: #http://services1.arcgis.com/4safsf2dgg32daf3/arcgis/admin/services/MyService.FeatureServer/0/updateDefinition token = gentoken(USERNAME, PASSWORD, REFFER) enableAttachment(token, fsURL)
import json, urllib, urllib2 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'} query_string = urllib.urlencode(query_dict) 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 return token['token'] def enableAttachment(token, fsURL): query_dict = {'updateDefinition': "{'hasAttachments':true}", #false 'f': 'json', 'token': token} query_string = urllib.urlencode(query_dict) attachResponse = urllib.urlopen(fsURL, urllib.urlencode(query_dict)) msg = json.loads(attachResponse.read()) print msg return USERNAME = " ______ " PASSWORD = " ______ " REFFER = "http://www.arcgis.com" fsURL = "http://services1.arcgis.com/<ORGANIZATION IDENTFIER/arcgis/admin/services/<SERVICE NAME>.FeatureServer/0/updateDefinition" # for example, a link may look like: #http://services1.arcgis.com/4safsf2dgg32daf3/arcgis/admin/services/MyService.FeatureServer/0/updateDefinition token = gentoken(USERNAME, PASSWORD, REFFER) enableAttachment(token, fsURL)
Just for anyone else who comes upon this thread...Jeff and I posted a blog with the python script to:-CreateMapSDDraft, Analyze, Stage and Upload for map documents to be pushed to ArcGIS.com as a hosted feature service /w overwrite and shared to arcgis.com turned on.http://blogs.esri.com/esri/arcgis/2013/04/23/updating-arcgis-com-hosted-feature-services-with-python/
Hello
This thread has been so helpful, and i would like to thank all of you in advance for all the information. I am facing similar situation as the original problem. This thread is three year old but i was wondering if there is any solution.
I have ARC 10.3 in my desktop . I am trying to publish mxd file automatically using python script , i used similar code posted in this thread. But it is showing error , unless i signed in manually through the ARCmap it wont publish the map. The error is as follows
ExecuteError: Failed to execute. Parameters are not valid.ERROR 000732: Server: Dataset My Hosted Services does not exist or is not supportedWARNING 001404: You are not signed in to ArcGIS Online.Failed to execute (UploadServiceDefinition).
Can you please post is as a file or text with line breaks included?Not an expert with Phyton
To modify the sddraft file and enable feature capability, the following code worked for me
# Read the sddraft xml. doc = DOM.parse(sddraft_output_filename) # Find all elements named TypeName. This is where the server object extension # (SOE) names are defined. typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: # Get the TypeName we want to enable. if typeName.firstChild.data == "FeatureServer": extension = typeName.parentNode for extElement in extension.childNodes: # Enable Feature Access. if extElement.tagName == 'Enabled': extElement.firstChild.data = 'true' if extElement.tagName == 'Info': for propArray in extElement.childNodes: if propArray.tagName == 'PropertyArray': for propSet in propArray.childNodes: for prop1 in propSet.childNodes: if prop1.tagName == "Key": if prop1.firstChild.data == 'WebCapabilities': # Turn on feature access capabilities if prop1.nextSibling.hasChildNodes(): prop1.nextSibling.firstChild.data = "Map,Query,Data" else: txt = doc.createTextNode("Map,Query,Data") prop1.nextSibling.appendChild(txt) # Output to a new sddraft. sddraft_mod_xml = 'sddraft_output_mod_xml' + '.sddraft' sddraft_mod_xml_file = os.path.join(draftsOutputDir, sddraft_mod_xml) f = open(sddraft_mod_xml_file, 'w') doc.writexml(f) f.close()
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.