Error 3 Datasource inaccessible .....but is it??

2 weeks ago
Labels (3)
New Contributor II

Heyho Hello,

relatively new to arcpy...arcmap...

Using ArcMap 10.7 on Win10

Trying to: Publish a service on an arcgis Server using a "standalone" Python Script, with the ArcMap's Python.exe set as interpreter. The layers use an oracle db. I will post some code below.

What works: Publishing through the ArcMap Interface, or through the Python window inside ArcMap. Creating an .sddraft externally using my script and publishing through the Arc Map python window. All layers are displayed correctly inside ArcMap and so are their datasources. Also: The same Script I've written works outside of ArcMap, on a different System with the same setup... 

Basically it's standard create .sddraft from .mxd, analyze it and publish code.... tried running as admin, setting arcpy.env.workspace to everything... including .sde file,  usually I set it to the folder including the .mxd .... this works on my other system... Checking Layers and Datasources, which Arcpy I'm using...hitting my head against the wall... repeatedly....

arcpy.mapping.ListBrokenDataSources(mxd) #returns all layer Datasources as broken so I tried the Method below
for brknItem in brknList:
print "\t" + brknItem.dataSource # returns path to the .sde
mapDoc.findAndReplaceWorkspacePaths(r"", r"C:\Users\<Name>\AppData\Roaming\Esri\<sdeName>.sde", {BOOLEAN})
# Only works with FALSE set... so it doesn't recognize the .sde as valid datasource? But its the same as in arcMap
import arcpy
import os
import sys

folder = raw_input("Enter a folder!")
wrkspc = r'D:/<folderName>/'+folder + "/"

if not os.path.isdir(wrkspc):
print "Error no such directory! " + wrkspc

inp = raw_input("Enter a .mxd file or type <all> in order to select all inside "+wrkspc+" ....:")
arcpy.env.workspace = wrkspc # tried setting to .sde and all sorts
arcpy.env.overwriteOutput = True

# mxd valid?
mapDoc = arcpy.mapping.MapDocument(wrkspc + inp +'.mxd')
print("Running ....")
except AssertionError:
print "Invalid file name! Hints: Do not include the .mxd ending, make sure the file is inside the "+wrkspc+" directory!"

con = r"C:\Users\<user>\AppData\Roaming\Esri\Desktop10.7\ArcCatalog\<FileName>.ags"

# Service Details
service = inp

# sddraft
sddraft = wrkspc + service + '.sddraft'
sd = wrkspc + service + '.sd'
summary = 'Test'
tags = 'MXD Upload Test'

# Definitiondraft
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'FROM_CONNECTION_FILE', con, False, folder, summary, tags)

# Analysis
analysis = arcpy.mapping.AnalyzeForSD(sddraft)

# Error is thrown in analysis.... tried skipping it.... error thrown during publish!

I feel like it's something obvious like a file path, an .env or something.... I just can't seem to find it...

Maybe someone has an idea! Thanks in advance!

0 Kudos
4 Replies
MVP Frequent Contributor

I'd guess it's permissions on the AppData folder.  Running it in ArcMap GUI is might be a different user than standalone Python.exe.

0 Kudos
New Contributor II

Might be some permission Issue, but running it as admin does not change anything f.ex.?

0 Kudos
MVP Frequent Contributor

"Also: The same Script I've written works outside of ArcMap, on a different System with the same setup... "

This would make me look at the two local paths you have in the script.  Does the user running the script have identical profiles on both machines?  Is the D:/Foldername the same on both machines?

Both of these settings are user specific, and could be why it works as expected on one machine, but not the other.  Also, different user woulnd't have access to the ags file in someone elses profile.


0 Kudos
New Contributor II

I did change the .ags file and the paths on the system accordingly, what I meant is the way I hardcoded the file paths etc. works fine on the other machine. 

0 Kudos