Rodrigo
Rodrigo

Reputation: 291

Pylance: Import "requests.packages.urllib3.util.retry" could not be resolved from source

I have the following line in my project

from requests.packages.urllib3.util.retry import Retry

Everything related to requests works with no problem, even the Retry

from requests import Session
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

requests = Session()

retry = Retry(connect=8, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
requests.mount("http://", adapter)
requests.mount("https://", adapter)

But for some unknown reason, Pylance complains about Retry module cannot be found.

What can be this warning?

enter image description here

Upvotes: 4

Views: 3200

Answers (1)

Steven-MSFT
Steven-MSFT

Reputation: 8411

Can you change it to:

from urllib3.util import Retry

The Pylance not that smart. This is what in the packages.py file:

for package in ('urllib3', 'idna', 'chardet'):
    locals()[package] = __import__(package)
    # This traversal is apparently necessary such that the identities are
    # preserved (requests.packages.urllib3.* is urllib3.*)
    for mod in list(sys.modules):
        if mod == package or mod.startswith(package + '.'):
            sys.modules['requests.packages.' + mod] = sys.modules[mod]

Pylance could not speculate rightly with these codes.

Upvotes: 7

Related Questions