DOI-BLM / requests-arcgis-auth

Authentication handler for using Esri ArcGIS for Server and Portal (ArcGIS Online) Token Authentication with Python Requests
22 stars 1 forks source link

ArcGISPortalAuth cannot complete token authentication if the HEAD method is not supported #27

Closed pfoppe closed 6 years ago

pfoppe commented 6 years ago

The ArcGISPortalAuth handler will first attempt token authentication. the first request uses the HEAD method in an attempt to see if an anonymous request can succeed, and if so it will not attempt Kerberos/NTLM (since it does not receive the HTTP status code 401 challenge).

Ran into an issue where the HEAD method was not supported, Updated code to execute a POST if an HTTP 405 is received on the HEAD request.

Possibly also an issue with ArcGISServerAuth, however have not experienced that yet.

pfoppe commented 6 years ago

sample code snippet:

s = requests.session()
s.auth = ArcGISPortalAuth(uname,pwd)
response = s.get(r'https://org.maps.arcgis.com/sharing/rest/portals/self?f=json')
>>> s.auth._last_request
<Response [405]>
>>> s.auth._last_request.request.url
'https://org.maps.arcgis.com//sharing/rest/generateToken'
>>> s.auth._last_request.request.method
'HEAD'
>>> s.auth._last_request.reason
'Method Not Allowed'