Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import could not be resolved problem in vscode pylance v2022.1.3 #2288

Closed
shaishap opened this issue Jan 26, 2022 · 2 comments
Closed

Import could not be resolved problem in vscode pylance v2022.1.3 #2288

shaishap opened this issue Jan 26, 2022 · 2 comments
Labels
waiting for user response Requires more information from user

Comments

@shaishap
Copy link

I have this line in my py source code (Python 3.10.1 64-bit):
from requests.packages.urllib3.exceptions import InsecureRequestWarning

Pylance extension in VSCode (running on Win10-64) reports problem:
Import "requests.packages.urllib3.exceptions" could not be resolved from source

Although requests package is properly installed and the import is valid.
Performing same import on CLI produces no error:

C:\Users\UUUU\Documents\scripts>python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from requests.packages.urllib3.exceptions import InsecureRequestWarning
>>> 
@erictraut
Copy link
Contributor

The type information for the requests library comes from the open-source typeshed repo.

There is a comment at the top of the reqests/packages/__init__.pyi stub that points to the issue you're seeing. It says "requests also imports urllib3 as requests.packages.urllib3, the stubs don't reflect that". This issue further explains what's happening. The maintainers of typeshed have apparently decided not to reflect the fact that urllib3 is re-exported from requests.packages. Since urllib3 is a separate library from requests, you can import directly from it rather than importing the (re-exported) reference to it from within requests.packages.

from urllib3.exceptions import InsecureRequestWarning

@judej judej added the waiting for user response Requires more information from user label Jan 26, 2022
@github-actions github-actions bot removed the triage label Jan 26, 2022
@heejaechang
Copy link
Contributor

dupe of this #597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

4 participants