Cannot import name 'get' from partially initialized module 'requests'

I have problem with requests package. In past requests was working, but today for no reason it stopped working. I am just importing requests and it cause error.

Code:

import requests

Error:

Traceback (most recent call last): File "d:\programovani\Python\SMSemail\test.py", line 1, in import requests File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests_init_.py", line 43, in import urllib3 File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3_init_.py", line 11, in from . import exceptions File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\exceptions.py", line 3, in from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 234, in create_module return self.load_module(spec.name) File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 209, in load_module mod = mod._resolve() File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 118, in _resolve return _import_module(self.mod) File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 87, in import_module import(name) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3312.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 71, in import email.parser File "d:\programovani\Python\SMSemail\email.py", line 1, in from requests import get ImportError: cannot import name 'get' from partially initialized module 'requests' (most likely due to a circular import) (C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests_init.py)

Screenshot:

Erorr

What I've tried:

import requests as re

Reinstalling package.

Note: File name is different

What is causing this error? Thank you.

Upvotes: 0

Views: 2078

Answers (1)

Timus
Timus

Reputation: 11321

The relevant parts of the traceback and my interpretation:

  • You're trying to run test.py. One of the imports in it is import requests:

Traceback (most recent call last):
File "d:\programovani\Python\SMSemail\test.py", line 1, in import requests

  • This results in a (normal) longer chain of imports. Somewhere along the line in the standard library's http.client module there's an import in line 71: import email.parser

File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3312.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 71, in import email.parser

  • Now trouble starts, because you have a file email.py in the same folder as test.py:

File "d:\programovani\Python\SMSemail\email.py", line 1, in from requests import get ImportError: cannot import name 'get' from partially initialized module 'requests' (most likely due to a circular import)

  • This alone should be enough to derail the program. So I'm a bit puzzled about the error message you get. I pretty much got the same as you when I tried to reconstruct your situation (one file test.py with import requests and another one named email.py in the same folder) but it ended with:

ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package

  • You have a from requests import get in email.py, so there is in fact a potential (unintended) circular import (program starts with importing requests and on the way to do that imports (parts of) request again -> circular):

File "d:\programovani\Python\SMSemail\email.py", line 1, in from requests import get

Solution: Renaming email.py should do the job, if I'm not mistaken.

Upvotes: 1

Related Questions