How to publish a feature service to ArcGIS Online from an mxd USING PYTHON?

25892
45
Jump to solution
03-25-2013 07:06 PM
BenoitMetzger
Deactivated User
Hi All,

I would like to automate publishing feature services - from an mxd using Python to my AG Online account.

I did this successfully manually using the menu: Share as -> Service, Publish a service - Feature Access Capabilities etc...

Using Python, I managed to publish the service definition file on AG Online using:
arcpy.mapping.CreateMapSDDraft()
arcpy.mapping.AnalyzeForSD()
arcpy.StageService_server()
arcpy.UploadServiceDefinition_server()

But I could not find a way to publish a feature service to AG Online! I must be missing something. Any help would be really appreciated.

Thanks in advance!
Tags (2)
45 Replies
KevinHibma
Esri Regular Contributor
The compressing error is from when trying to make the .SD file.
I think theres a few things that could cause it.
A couple guesses:
--do you have any locks on the data you're consolidating, or are they accessed by something else? (not allowing them to be put into the sd file)
--you have write access to the directory you're trying to create the .sd in?
--from your screen shot you're executing against 64bit python, but the trace back shows its in 32bit python. Not sure how/why they're crossed. Try running your script from the 32bit Python (note the lack of 'x64' in the path for 32bit).
0 Kudos
KevinBingham
Emerging Contributor
Kevin-

-- I do not think that there are any locks on the data I am consolidating

-- I do have write access to the directory where I am trying to update that .SD file

-- Previously I tried to execute the script from 32 bit python but received the error "c:\Python27\ArcGIS10.2\python.exe is not a valid Win32 application."

Thanks again,

Kevin
0 Kudos
KevinBingham
Emerging Contributor
I made it past the last error only to encounter another error related to publishing.  An image (with the error message) is attached.

Thanks,

Kevin
0 Kudos
PhiliposMelake
Deactivated User

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 supported
WARNING 001404: You are not signed in to ArcGIS Online.
Failed to execute (UploadServiceDefinition).

0 Kudos
GisGKAuckland
Deactivated User

Can you please post is as a file  or text with line breaks included?

Not an expert with Phyton

0 Kudos
arahman_mdmajid
Frequent Contributor

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()
Abdur Rahman
GIS Developer
0 Kudos