I am trying to publish a draft service definition using arcpy.mapping.CreateMapSDDraft and am getting the referenced Assertion Error. I've tried the responses to users with similar questions with no luck.

Here is the code I am working with:

# Import system modules
import arcpy, os, sys
from arcpy import env

# Set local variables
wrkspc = r"\\intruder11\grc\sw\core\dev\gp\hosted_services_sp"
mapDoc = arcpy.mapping.MapDocument(wrkspc + 'NoMap.mxd')
outputFolder = r"\\intruder11\grc\sw\core\dev\gp\hosted_services_sp"
sddraft = mapDoc + service + '.sddraft'
summary = 'Test of publishing automation'
tags = 'CNR Southwest, dev, test, acc'

# Sign-in to Portal for ArcGIS
logger.info('Signing into built-in ACC account')
arcpy.SignInToPortal_server("--","--", "https://--")

### create service definition draft
analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'MY_HOSTED_SERVICES',con, True, None, summary, tags)

### Sign out from ArcGIS Online
  • 2
    Your mapDoc variable has no backslash between your workspace and MXD names.
    – PolyGeo
    Commented Jul 3, 2020 at 23:33
  • @PolyGeo can you help me with the syntax? Struggling to determine the placement of the backslash. Thanks
    – r2dave2
    Commented Jul 4, 2020 at 0:04
  • 4
    os.path.join(wrkspc, 'NoMap.mxd')
    – user2856
    Commented Jul 4, 2020 at 2:58

1 Answer 1


Your mapDoc variable has no backslash between your workspace and MXD names. One way to address that is by using Python string formatting.

I would replace this:

mapDoc = arcpy.mapping.MapDocument(wrkspc + 'NoMap.mxd')

with this:

mapDoc = arcpy.mapping.MapDocument(r'{0}\{1}'.format(wrkspc,'NoMap.mxd'))
  • Why not arcpy.mapping.MapDocument(os.path.join(wrkspc, 'NoMap.mxd'))? I feel it's always better to let the system create the filepath rather than construct it myself, so just wondering
    – Midavalo
    Commented Jul 5, 2020 at 19:10
  • @Midavalo it’s a personal preference. I don’t like importing an additional library when something’s so easy to do without.
    – PolyGeo
    Commented Jul 5, 2020 at 19:34
  • that makes sense. I guess I'm just in the (possibly bad) habit of always adding import os :)
    – Midavalo
    Commented Jul 5, 2020 at 19:53
  • @Midavalo The way I do it probably stems from teaching so many non-programmers to code with ArcPy and Python. Python string formatting is so useful for constructing messages, SQL expressions paths, etc that I think it’s worth mastering it’s syntax early.
    – PolyGeo
    Commented Jul 5, 2020 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.