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.
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?
-
1Running 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– nmtoken2022年07月28日 08:41:35 +00:00Commented Jul 28, 2022 at 8:41
-
The data has very little amount of features. Adding manually works in less than 5 seconds.Ahmad Raji– Ahmad Raji2022年07月28日 11:06:07 +00:00Commented Jul 28, 2022 at 11:06
1 Answer 1
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.
Explore related questions
See similar questions with these tags.