0

This is the code:

from .packages import six 
from .packages.six.moves.http_client import HTTPConnection as _HTTPConnection
from .packages.six.moves.http_client import HTTPException  # noqa: F401

And the problem Import ".packages.six.moves.http_client" could not be resolved Pylance is raised at line 2 & 3.

Similar post that I found on this website is: Cannot import HTTPConnection from six.moves.http_client however I couldn't follow along with the answer given there.

Edit:1 Furthermore, When I run the file, ImportError: attempted relative import with no known parent package is raised at line from .packages import six in above code.

Edit:2 This webpage: https://techwithtech.com/importerror-attempted-relative-import-with-no-known-parent-package/ clearly explains the ImportError mentioned in Edit:1 but I am unable to fix it. So What am I missing here?

The file structure of connection.py and six.py are underlined in the picture below.

The files are underlined where as the code is wrapped in bracket

Raj1969
  • 21
  • 6
  • Is that typing problem, or raise when execute app. – Javohir Elmurodov Apr 15 '22 at 05:46
  • it's typing problem I guess, cause the line `.packages.six.moves.http_client` gets underlined/highlighted and also certain `ImportError ` is returned (read edited post) when I run it. – Raj1969 Apr 15 '22 at 06:02
  • So if it's typing problems it depends to your IDE or Editor – Javohir Elmurodov Apr 15 '22 at 11:24
  • If your editor is VS code you can `#type: ignore` in order to disable – Javohir Elmurodov Apr 15 '22 at 11:53
  • Hello @Javohir I implemented your fix `#type: ignore` but was greeted with same ``ImportError: attempted relative import with no known parent package" so I made few changes at line 12 to 14 (look at the picture above) by using this code : `from urllib3.packages import six from .packages.six import HTTPConnection as _HTTPConnection from .packages.six import HTTPException # noqa: F401` however,now I get this `ImportError: cannot import name 'HTTPConnection' from 'urllib3.packages.six'` – Raj1969 Apr 16 '22 at 10:24

0 Answers0