I am having trouble with a arcpy script. I'm actuall not that familiar with python in general, and the current issue is really making me sick.
On a new environment, I installed a new Database and I want to setup there the same maintenance task as we already have on another environment. Part of this maintenance is a python script for compress, etc. But on the new environment the scripts aren't working. It always runs into error "TypeError: Could not open SDE workspace"
So I made some tests on the current environment and found some very strange behaviour.
I have the following script (reduced to only few lines)
conn = 'C:\SDE\da.sde'
the file da.sde exists.
But when I rename the file to test.sde, and change it of course in the pythin script, it throws:
Traceback (most recent call last):
File "C:\SDE\test.py", line 5, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\__init__.py", line
1677, in AcceptConnections
return gp.acceptConnections(sde_workspace, accept_connections)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\geoprocessing\_bas
e.py", line 479, in acceptConnections
return self._gp.AcceptConnections(sde_workspace, accept_connections)
TypeError: Could not open SDE workspace.
(This is also the actual error I always get on the other environment.)
Switching both back to da.sde, works again.
I've testes several different filenames.
"da.sde" - works!
"test.sde" - fail
"datest.sde" - works
"abcde.sde" - fail
"wtf.sde" - works
"lmgtfy.sde" - works
"prod_sde.sde" - works
"b_prod_sde.sde" - fails
I am not sure that the nameing is related to the issue on the other environment. But I got a little desperate with it, so that I hope unterstanding the nameing issue, may help me to make the script run elsewhere.
pth = "C:\SDE\test.sde" print(pth) # ---- ooops C:\SDE est.sde pth = "C:\SDE\abcde.sde" # ---- try again print(pth) # ---- C:\SDEbcde.sde
start by raw encoding your file paths
conn = r'C:\SDE\da.sde' # ---- not the r in front of the path
Now raw encode them
pth = r"C:\SDE\test.sde" print(pth) C:\SDE\test.sde pth = r"C:\SDE\abcde.sde" print(pth) C:\SDE\abcde.sde
You can use double backslashes or forward slashes if you don't want to use the little 'r'
I've tried it, and now it works fine on current environment, independent on filename, thanks!
However, on the other environment it has no effect. still always getting the error. Printing the paths show all in the right way. Workspace works fine in ArcCatalog.
This works with python executed in ArcCatalog, gut not here.
So obviously my initial issue on the other environment is not related to file names.
I checked out all the links I found on google.
- Everything is in 64bit, tried also both pythons
- arcpy.Exists(r"C:\SDE\test.sde") returns true
- setting arcpy.env.workspace to anything has no effect (setting it to C:\SDE and the connection fiel just test.sde)
I got myself turned around reading through this thread. After changing how you handle path names: