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?