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:

  1. urllib3 version was not set in our requirements.txt

  2. pip install -r requirements.txt

  3. Open connection using arcgis.GIS(url=…, username=…, password=…)

  4. 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)

Most upvoted comments

@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 urllib3 with arcgis 191 in April

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 urllib3 with arcgis 191 in May

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:

a = requests.adapters.HTTPAdapter(
                max_retries=Retry(
                    total=2,
                    backoff_factor=1,
                    **method_whitelist**=frozenset(
                        [
                            "POST",
                            "DELETE",
                            "GET",
                            "HEAD",
                            "OPTIONS",
                            "PUT",
                            "TRACE",
                        ]
                    ),
                )
            )

To the following:

a = requests.adapters.HTTPAdapter(
                max_retries=Retry(
                    total=2,
                    backoff_factor=1,
                    **allowed_methods**=frozenset(
                        [
                            "POST",
                            "DELETE",
                            "GET",
                            "HEAD",
                            "OPTIONS",
                            "PUT",
                            "TRACE",
                        ]
                    ),
                )

arcgis_issue_allowed_methods

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

  1. Clone tutorial repo, install arcgis using pip (could be the problem?)
git clone git@github.com:Esri/arcgis-python-api.git

python -m venv venv # Python 3.8.5

pip install arcgis
  1. Try running cell 37 in install-and-set-up.ipynb (modified here to show versions, traceback)
import arcgis
import requests
import urllib3
import traceback
print(f"arcgis version "+arcgis.__version__)
print(f"requests version "+requests.__version__)
print(f"urllib version "+urllib3.__version__)
try:
    my_gis = arcgis.gis.GIS()
    m = my_gis.map()
    m
except:
    print(traceback.format_exc())

Output:

arcgis version 2.1.0.3
requests version 2.30.0
urllib version 2.0.2
Traceback (most recent call last):
  File "...\AppData\Local\Temp\ipykernel_8736\4182468458.py", line 11, in <module>
    my_gis = arcgis.gis.GIS()
  File "...\venv\lib\site-packages\arcgis\gis\__init__.py", line 586, in __init__
    raise e
  File "...\venv\lib\site-packages\arcgis\gis\__init__.py", line 525, in __init__
    self._portal = _portalpy.Portal(
  File "...\venv\lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 208, in __init__
    self.con = Connection(
  File "...\venv\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 353, in __init__
    self._create_session()
  File "...\venv\lib\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'
  1. Make edit to line 529 of .arcgis\gis_impl_con_connection.py as mentioned above, rerun cell (back to original code)
from arcgis.gis import GIS
my_gis = GIS()
m = my_gis.map()
m

This runs successfully up until the last line displaying the map,

m

It then encounters a problem, something with IPyWidget? (output below)

in IPythonDisplayFormatter.__call__(self, obj)
    920 method = get_real_method(obj, self.print_method)
    921 if method is not None:
--> 922     method()
    923     return True

File ...\arcgis\widgets\_mapview\_mapview.py:1008, in MapView._ipython_display_(self)
   1002 """Override the parent ipython display function that is called
   1003 whenever is displayed in the notebook. Display a blank area
   1004 below the map widget that can be controlled via a display handler
   1005 set to self._preview_image_display_handler.
   1006 """
   1007 self._setup_gis_properties(self.gis)
-> 1008 super(MapView, self)._ipython_display_()
   1009 self._preview_image_display_handler = display(
   1010     HTML(self._assemble_img_preview_html_str("")),
   1011     display_id="preview-" + str(self._uuid),
   1012 )
   1013 self._preview_html_embed_display_handler = display(
   1014     HTML(self._assemble_html_embed_html_str("")),
   1015     display_id="preview-html-" + str(self._uuid),
   1016 )

AttributeError: 'super' object has no attribute '_ipython_display_'

But either way, the call to

GIS()

succeeds. Attaching a screenshot of what I see in the Jupyter cell after getting the above error oputput

failed_to_load_model_class