ListFields Not Working for Feature Classes in Enterprise SDE

1222
4
Jump to solution
05-11-2021 12:25 PM
EvanMyers1
Occasional Contributor

I have been running into a strange issue with a code I am working on and it only happens when I am working with data formatted like this.  This is from a script that uses a Multivalued Parameter. See below:

 

fc = "'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.ControlValve';'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wFitting';'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wHydrant'"

fclist = fc.split(";")

for each in fclist:
    fieldnames = [f.name for f in arcpy.ListFields(each)]
    print fieldnames

 

From this I get the error: 

Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\__init__.py", line 1139, in ListFields
return gp.listFields(dataset, wild_card, field_type)
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\geoprocessing\_base.py", line 346, in listFields
self._gp.ListFields(*gp_fixargs(args, True)))
IOError: "'Database Connections\Prod@GISdb.OSA.sde\Prod.Water\Prod.ControlValve'" does not exist

 

I am at a loss with this error as it appears quite often.  If anyone has any points how to avoid this error I would be extremely grateful!

0 Kudos
1 Solution

Accepted Solutions
EvanMyers1
Occasional Contributor

It turns out it was the single quotes ( ' ) around each file path that was giving me issues.  Never knew those would prevent arcpy.Describe and arcpy.ListFields from working 😵

View solution in original post

0 Kudos
4 Replies
PhilLarkin1
Occasional Contributor III

You could use arcpy.describe and .exists to validate the connection file is valid. 

0 Kudos
DavidPike
MVP Frequent Contributor

maybe some raw formatting on the strings 

fc = "r'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.ControlValve';r'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wFitting';r'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wHydrant'"

fclist = fc.split(";")

for each in fclist:
    print (each)
    fieldnames = [f.name for f in arcpy.ListFields(each)]
    print fieldnames
0 Kudos
DanPatterson
MVP Esteemed Contributor

Beyond not using paths that contain spaces, and punctuation (which can cause inconsistent issues).

Set your works space and after parsing the featureclass/feature/table names, do a final check to see if it "exists"

arcpy.env.workspace = "c:/your_path/your.gdb"
# ------ does it exists
if arcpy.Exists("your_fc"):
    Do stuff

... sort of retired...
0 Kudos
EvanMyers1
Occasional Contributor

It turns out it was the single quotes ( ' ) around each file path that was giving me issues.  Never knew those would prevent arcpy.Describe and arcpy.ListFields from working 😵

0 Kudos