Search code examples
python-3.xurllib3

python urllib : TypeError: 'module' object is not callable


when I follow the instructions on the official website of urllib3 and run

import urllib3
resp = urllib3.request("GET", "https://httpbin.org/robots.txt")
resp.status, resp.data

I get the error

---------------------------------------------------------------------------
TypeError      Traceback (most recent call last)
some_path/main.ipynb Cell 1 in ()
      1 import urllib3
----> 2 resp = urllib3.request("GET", "https://httpbin.org/robots.txt")
      3 resp.status, resp.data

TypeError: 'module' object is not callable

What did I do wrong?


Solution

  • It looks like the version of urllib3 installed in your system is 1.x.x There are several changes made in urllib3 in 2.0.0 (https://urllib3.readthedocs.io/en/stable/changelog.html#id5)

    Check version of urllib3:

    pip3 show urllib3

    The documentation you are referring is as per current version.

    You can either use your current version of urllib3 or upgrade to latest version.

    If you want to use your current version of urllib3 then you can refer to this documentation (https://urllib3.readthedocs.io/en/stable/user-guide.html)

    and if you want to upgrade to latest version, then here is the command to do this.

    python3 -m pip install --upgrade --user urllib3