4

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

Rodrigo
  • 135
  • 4
  • 45
  • 107

1 Answers1

7

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.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13