2

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 28, 2022 at 6:19
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. Commented Jul 28, 2022 at 8:41
  • The data has very little amount of features. Adding manually works in less than 5 seconds. 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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Aug 1, 2022 at 11:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.