Error: OSError: Tunnel connection failed: 407 Proxy Authorization Required

Error Message

Attempts to run a Python script and log in to Portal for ArcGIS fail, and return the following error:

OSError: Tunnel connection failed: 407 Proxy Authorization Required

The following shows a sample code that may result in the error:

import arcgis

con = arcgis.gis.GIS(url="https://TEST.maps.arcgis.com", username="user1") 



There are two possible causes:

  • The connection to the selected portal is blocked by the proxy on the network. This occurs if the connection uses a custom proxy, for example, a company public key infrastructure with corresponding certificates.
  • The script is unable to automatically recognize the proxy used by the Portal for ArcGIS and ArcGIS Server configured certificate.

Solution or Workaround

Use the following solutions to fix the issue:

Whitelist the following ArcGIS Online domains:

  • https://*.arcgis.com
  • https://*.arcgisonline.com
  • https://*.blob.core.windows.net
  • https://*.esri.com

Declare the proxy_port parameter

To enable the script to recognize the custom port, the proxy_port parameter must be declared and added to the full script. The following shows the sample code:

  • For ArcGIS Online login:
gis = GIS(proxy_host='', proxy_port=8888)
  • For a secured proxy:
gis = GIS(url="https://arcgis.com", username="user1", password="password1", proxy_host="<username>:<password>@<proxyname>”, proxy_port=8888, verify_cert=False)

Related Information