1

I have a Python script tool that makes use of a feature layer hosted on a map server. Originally, I got the layer by making a feature layer using the code below.

lyr = arcpy.MakeFeatureLayer_management(URL)

The above code works fine for most URLs but doesn't work for secured connections. We access secured connections using tokens. I can add the layer manually on ArcGIS by adding data from path (URL) as in the case in the image below.

enter image description here

I noticed that the token needs to be passed as a parameter but can't figure out a way to do this. I've tried

URL = "http://arc-gis-svr:xxxxxxxxxxxxxxxxxxxxxxx/mapserver/11?token=triuexxxxxxxxxhhsjd"
lyr = lyr = arcpy.MakeFeatureLayer_management(URL)

The code above still doesn't work. It doesn't throw an error and runs for a very long time and I have to cancel it.

How can I pass the token as a parameter in the code?

2
  • 1
    Running for a very long time doesn't immediately suggest that passing the token doesn't work, it suggests that the server accepts the token but you are trying to fetch too much data. if the token isn't accepted you'd expect a fast failure.
    – nmtoken
    Commented Jul 28, 2022 at 8:41
  • The data has very little amount of features. Adding manually works in less than 5 seconds.
    – Ahmad Raji
    Commented Jul 28, 2022 at 11:06

1 Answer 1

0

A possible solution (untested) is to add the layer to a map in ArcGIS Pro, so its all working then save that as a Layer File by right clicking on the layer in the Contents pane >Sharing > Save as Layer File then reference that in your script. I just don't know if this works for secured layers.

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.