arcgis-python-api: Unable to connect with latest urllib3
Describe the bug
When using the latest version of urllib3
, the exception TypeError: __init__() got an unexpected keyword argument 'method_whitelist'
is thrown when connecting to ArcGIS.
To Reproduce
Steps to reproduce the behavior:
-
urllib3
version was not set in our requirements.txt -
pip install -r requirements.txt
-
Open connection using arcgis.GIS(url=…, username=…, password=…)
-
The exception is thrown. The relevant part of the stack trace is:
self.gis = arcgis.GIS(url=os.environ['ARCGIS_URL'],
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/arcgis/gis/__init__.py", line 586, in __init__
raise e
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/arcgis/gis/__init__.py", line 525, in __init__
self._portal = _portalpy.Portal(
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/arcgis/gis/_impl/_portalpy.py", line 208, in __init__
self.con = Connection(
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/arcgis/gis/_impl/_con/_connection.py", line [35](https://github.com/EcoNet-NZ/inaturalist-to-cams/actions/runs/4890064802/jobs/8729146920#step:7:36)3, in __init__
self._create_session()
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/arcgis/gis/_impl/_con/_connection.py", line 526, in _create_session
max_retries=Retry(
TypeError: __init__() got an unexpected keyword argument 'method_whitelist'
See https://github.com/EcoNet-NZ/inaturalist-to-cams/actions/runs/4890064802/jobs/8729146920 for our failing GitHub Actions job if any more details are needed.
Expected behavior
The arcgis-python-api
should be updated to work with the latest urllib3
which has removed the deprecated method_whitelist
argument.
Platform (please complete the following information):
- OS: Ubuntu
- Python API Version 3.9
Additional context
A workaround is to add pre-2.0 version of urllib3
to requirements.txt:
pyinaturalist==0.18.0
arcgis==2.1.0.3
urllib3==1.26.15 # Fix this version to avoid TypeError: __init__() got an unexpected keyword argument 'method_whitelist'
func_timeout==4.3.5
pytz==2023.3
python-dateutil==2.8.2
retry==0.9.2
git+https://github.com/behave/behave@v1.2.7.dev2
behave_html_formatter==0.9.10
pyhamcrest==2.0.4
factory_boy==3.2.1
flake8==6.0.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 26 (11 by maintainers)
@nanaeaubry thank you, I was just about to edit to confirm that using
urllib3@1.26.15
seems to have worked for me as well.This has been resolved for the next release, thank you!
For publishing Azure Functions that use arcgis api, I am using arcgis==1.9.1 per this thread: https://community.esri.com/t5/arcgis-api-for-python-questions/suddenly-can-t-build-and-deploy-python-azure/td-p/1205235 As mentioned in this original post, this week we started getting the error:
Error: init() got an unexpected keyword argument ‘method_whitelist’
I looked at the urllib version that got installed when I created a project a while ago using pip install arcgis==1.9.1. The version of urllib3 that got installed at that time was 1.26.12
Today I created a fresh new Azure Function and used pip install arcgis==1.9.1 and the version of urllib3 that got installed today is 2.0.2
So, something changed recently in Esri’s specification of what version of urllib3 to use, even for older versions of arcgis api. Apparently the update in terminology to replace “whitelist_methods” with “allowed_methods” has proceeded in urllib3 but has not been updated in arcgis api.
Thank you for reporting this. The urllib3 wasn’t supposed to change this until v2.0.0, they recently pushed an update and I’ll see if they moved the deprecation back. Thank you for reporting this.
Unfortunately, deploying to Azure Functions I’m stuck at 1.9.1
@alecStewart1 Yes, this is expected. It is fixed at 2.2.0 which will be released in September. You need to install a urllib version <2 first before installing arcgis 2.1.0.3 to fix this as of now
@nigelcharman Yes we will pin this as well, thanks for letting us know!
@nanaeaubry , Ohh.
I’ve misunderstood, thanks!
By the way, It’s fanstatic to receive feedback so quickly. ❤️
That makes sense, looks like the 4/26/2023 update to 2.0.0 was when they deprecated “method_whitelist”. https://urllib3.readthedocs.io/en/stable/changelog.html#id3 This corresponds with the timeframe our stuff stopped working (next deployment after 4/26).
Hello,
I just wanted to weigh in on this, thank you all very much for posting such good descriptions.
Maybe this is just obvious, but I went ahead and tested out by editing line 529 of .arcgis\gis_impl_con_connection.py. I changed:
To the following:
I hope this helps, again maybe this is obvious, but this seems to confirm @nigelcharman 's hunch that this was an issue with URLlib naming vs. some bigger issue.
I’m brand new to arcgis so super glad to see that this is an active community!!!
@achapkowski updating my comment with better steps to reproduce
Working on VSCode
Output:
This runs successfully up until the last line displaying the map,
It then encounters a problem, something with IPyWidget? (output below)
But either way, the call to
succeeds. Attaching a screenshot of what I see in the Jupyter cell after getting the above error oputput