I have the following code that I want to use to access a secured arc rest api site and query a layer to return the data in json. I can do this manually by going to the rest site in a browser, signing in, and using the query page to return data. And the code below (mostly copied from the web) works on non secured sites, without username and password.
But when I try to access the site using the password, I get the error:
RuntimeError: RecordSetObject: Cannot open table for Load
How can I do log in programmatically to get this data? Thanks.
baseURL = "http://company/arcgis/rest/services/Maps/CityMapServer/6/query"
where = "1=1"
fields = "*"
user = "user"
password = "pass"
query = "?where={}&outFields={}&returnGeometry=true&f=json&auth=({},{})".format(where, fields, user, password)
fsURL = baseURL + query
fs = arcpy.FeatureSet()
fs.load(fsURL)