Use Python-API behind Proxy

16021
27
06-13-2017 05:47 AM
MU
by
New Contributor III

Hi,
I'm trying to use the new Python-API with our on-premise system. Our company runs it's own public key infrastructure, so I've configured Portal for ArcGIS with a corresponding certificate. Furthermore, there is a company-wide proxy that we are using.

As a first throw, I'd like to connect to ArcGIS Online by doing this:

from arcgis.gis import GIS
my_gis = GIS()

This crashes with:

c:\Program Files\ArcGIS\Pro\bin\Python>python.exe "C:\temp\Test.py"
Traceback (most recent call last):
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\urllib\request.py", line 1254
, in do_open
 h.request(req.get_method(), req.selector, req.data, headers)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 1106, i
n request
 self._send_request(method, url, body, headers)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 1151, i
n _send_request
 self.endheaders(body)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 1102, i
n endheaders
 self._send_output(message_body)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 934, in
 _send_output
 self.send(msg)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 877, in
 send
 self.connect()
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 1252, i
n connect
 super().connect()
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 853, in
 connect
 self._tunnel()
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\http\client.py", line 832, in
 _tunnel
 message.strip()))
OSError: Tunnel connection failed: 407 authenticationrequired

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "C:\temp\Test.py", line 7, in <module>
 my_gis = GIS()
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis\gis.py",
 line 95, in __init__
 verify_cert=self._verify_cert, client_id=self._client_id)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis\_impl\po
rtalpy.py", line 160, in __init__
 client_id=client_id)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis\_impl\co
nnection.py", line 281, in __init__
 self.login(username, password, expiration, client_id)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis\_impl\co
nnection.py", line 504, in login
 resp = self.post('', { 'f': 'json' }, add_token=False) # probe portal to fin
d auth scheme
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis\_impl\co
nnection.py", line 1031, in post
 resp = opener.open(url, data=encoded_postdata.encode())
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\urllib\request.py", line 466,
 in open
 response = self._open(req, data)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\urllib\request.py", line 484,
 in _open
 '_open', req)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\urllib\request.py", line 444,
 in _call_chain
 result = func(*args)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\urllib\request.py", line 1297
, in https_open
 context=self._context, check_hostname=self._check_hostname)
 File "c:\Program Files\ArcGIS\Pro\bin\Python\lib\urllib\request.py", line 1256
, in do_open
 raise URLError(err)
urllib.error.URLError: <urlopen error Tunnel connection failed: 407 authenticati
onrequired>

Is it related to some proxy issues and if yes, where do I have to configure the proxy?

Tags (2)
27 Replies
MU
by
New Contributor III

After configuring everything from scratch, I ended up with this: urllib.error.URLError: <urlopen error [WinError 10061]

A bit of searching the web confirms my suspicion that it is related to the proxy. Our proxy requires authentication and urlopen should actually consider Windows' proxy settings (configured within Internet Explorer), but it doesn't seem to work.

I've also tested whether the environment variables http_proxy or https_proxy make any difference - nope

So any help would be appreciated!

BenjaminBlackshear
New Contributor III

I am also struggling with this, there is no documentation related to configuring proxy settings, ESRI please publish this.

RohitSingh2
Esri Contributor

The Python API currently doesn't support proxies. We will be adding this support to the next release (release data TBD). Till then, can you see if you can use the workaround at  The lazy Flimbot: Using ArcGIS API for Python (1.0.1) behind a proxy ?

ericjetter
New Contributor II

Hi,
do you know the next release date? we need the proxy support.
Thanks,

Eric

RohitSingh2
Esri Contributor

We released v1.2.3 with support for proxy servers on Friday.

In addition to explicitly named variable, the GIS object supports optional key word
arguments

================    ===============================================================
**kwargs**          **Description**
----------------    ---------------------------------------------------------------
proxy_host          optional string, host name of the proxy server
----------------    ---------------------------------------------------------------
proxy_port          optional integer, proxy host port.  The default is 80.
================    ===============================================================


Usage Example: Anonymous ArcGIS Online Login with Proxy

gis = GIS(proxy_host='127.0.0.1', proxy_port=8888)
ericjetter
New Contributor II

Hi,

thanks for your answer.

But the new version is not available on https://developers.arcgis.com/python/?

Eric

0 Kudos
RohitSingh2
Esri Contributor

It is available on the esri conda channel - Files :: Anaconda Cloud 

We'll be updating the developer site later this month.

RebeccaStrauch__GISP
MVP Emeritus

rsingh-esristaff ,

I used

conda upgrade -c esri arcgis

in the Anaconda Prompt window (today) based on the instructions in https://community.esri.com/groups/arcgis-python-api/blog/2017/07/17/arcgis-api-for-python-12-release...  and it looks like is grabbed the 1.2.3 release. 

Does the above command grab from the esri conda channel ?  And if is does, will it always grab a "ready for release" version and not a preliminary release?

Note: I found using the command line has worked better than trying to do the upgrade thru Pro...however, I may be doing that incorrectly or mixing apples with oranges.  However, the above command is very straight forward for me.

0 Kudos
RohitSingh2
Esri Contributor

The command

conda upgrade -c esri arcgis

grabs from the esri conda channel and it will always grab the latest released version. It will not get a preliminary version.

In this command "-c esri" specifies that it should use the esri conda channel.

If you wish you upgrade to a specific version you can specify it as:

conda upgrade -c esri arcgis=1.2.0