Select to view content in your preferred language

Using Arcpy With Authenticated Server

209
5
11-25-2024 05:33 AM
CodyPatterson
Frequent Contributor

Hey all,

I assume this is a relatively simple question with a relatively simple answer. When opening this ArcPro project file, I am presented with a request to enter credentials:

CodyPatterson_0-1732541465038.png

Even though I select Windows Credential Manager, it does not save, but that's fine for this purpose.

When accessing this through Arcpy or attempting to at least, I get this:

CodyPatterson_1-1732541562585.png

I assume this is due to the authentication, we do not have access to the REST environment, so I cannot use the API for Python, so Arcpy must be employed.

How should I accomplish this?

Thanks in advance!

Cody

0 Kudos
5 Replies
TonyAlmeida
Frequent Contributor

I would check to make sure the layer is correct.

test = map.listLayers("FiberCable")[0]
print(f"Selected layer: {test.name}")  # Check the layer name
print(f"Data source: {test.dataSource}")  # Verify the data source path

arcpy.MakeFeatureLayer_management(test.dataSource, 'testinglayer')

 

 

 

0 Kudos
CodyPatterson
Frequent Contributor

Hey @TonyAlmeida 

Great suggestion! This actually showed me whether or not I was logged in on the layer, appears so:

CodyPatterson_0-1732560490281.png

The USER item is filled with the username, not sure if it actually is logged in, but it unfortunately did not work.

Cody

0 Kudos
TonyAlmeida
Frequent Contributor

 Try using the layer object returned by the MakeFeatureLayer result, line 8.

test = map.listLayers("FiberCable")[0]

# Verify the original layer details
print(f"Original layer: {test.name}")
print(f"Data source: {test.dataSource}")

# Returned layer object
result = arcpy.MakeFeatureLayer_management(test.dataSource, 'testinglayer')

# Get the layer object from the result
testing_layer = result.getOutput(0)

# Now work with `testing_layer`
print(f"Selected layer: {testing_layer.name}")  # Layer name
print(f"Data source: {testing_layer.dataSource}")  # Data source path

 

 

0 Kudos
CodyPatterson
Frequent Contributor

Hey @TonyAlmeida 

Thank you for another suggestion, unfortunately this didn't work either. This time it's related to a bug regarding the MakeFeatureLayer using the Feature Service link. I was told by ESRI support that this was too advanced of an issue to work through so it was marked as a Known Limit which means it will not be worked on.

This is the error I received:

CodyPatterson_0-1732565023300.png

Bug link: https://my.esri.com/#/support/bugs/bugs?bugNumber=BUG-000144037

Cody

0 Kudos
TonyAlmeida
Frequent Contributor

I didn't know that. Thanks for sharing!

0 Kudos