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:
What I've tried:
import requests as re
Reinstalling package.
Note: File name is different
What is causing this error? Thank you.
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.
Related
I have installed pyrebase library and tried importing it Like
import pyrebase
It gives following Error and i dont know how to fix it!
Traceback (most recent call last):
File "fire.py", line 1, in <module>
import pyrebase
File "env\lib\site-packages\pyrebase\__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "env\lib\site-packages\pyrebase\pyrebase.py", line 1, in <module>
import requests
File "env\lib\site-packages\requests\__init__.py", line 63, in <module>
from . import utils
File "env\lib\site-packages\requests\utils.py", line 27, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "env\lib\site-packages\requests\cookies.py", line 172, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Tried following some stack overflow advice but those wewe not specific.
This happens because pyrebase uses a deprecated collections module. Fixing this issue is possible but it leads to a chain of issues, I would recommend you to used pyrebase4 instead.
I have tried to run my python app on my website, but I get the error
"No module named jsonpickle"
even though I have jsonpickle installed. I even found the file path, and jsonpickle is there, but still my app says "no module named jsonpickle"
i logged into the SSH and typed
source /home/dsmproto/virtualenv/main.py/3.8/bin/activate && cd /home/dsmproto/main.py
then i installed all of the modules i needed, specifically
pip install jsonpickle
and then i go to run my app and i get the error:
stdin: is not a tty
Traceback (most recent call last):
File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in <module>
app_module = load_app()
File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
return imp.load_source('passenger_wsgi', startup_file)
File "/home/dsmproto/main.py/passenger_wsgi.py", line 1, in <module>
from main import main as application
File "/home/dsmproto/main.py/main.py", line 2, in <module>
from wallet import wallet
File "/home/dsmproto/main.py/wallet.py", line 3, in <module>
from blockchain_utils import blockchain_utils
File "/home/dsmproto/main.py/blockchain_utils.py", line 3, in <module>
import jsonpickle
ImportError: No module named jsonpickle
Is that enough info for you guys?
Please help, thanks!
I am trying to import Biopython modules on my Mac terminal but its throwing following error. It will be very helpful if someone could help me fix this issue.
>>> from Bio import SeqIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/Bio/SeqIO/__init__.py", line 317, in <module>
from Bio._py3k import basestring
File "/Library/Python/2.7/site-packages/Bio/_py3k/__init__.py", line 235, in <module>
from urllib2 import urlopen, Request
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1230, in <module>
import ssl
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 133, in <module>
PROTOCOL_SSLv23 = PROTOCOL_TLS
NameError: name 'PROTOCOL_TLS' is not defined
Thank you!!!
PROTOCOL_TLS was added in 2.7.13.
Oddly, it looks like your error is in the ssl module itself which should know about this constant; I'm guessing something is terribly wrong with the _ssl module that provides the C interface to OpenSSL. I know Macs and OpenSSL have been a headache for the CPython developers, but I can't give you much more than this.
Try doing import _ssl and making sure _ssl.PROTOCOL_TLS exists and that _ssl comes from a sane file system location (somewhere near the ssl module itself); if it doesn't, your _ssl module is a problem. It's possible you've got a pre-2.7.13 _ssl module somehow included in your sys.path, even as a post-2.7.13 ssl module is being loaded, which expects to find PROTOCOL_TLS in _ssl, and explodes when it can't be found.
I just had this problem while trying to import mathplotlib.
This was the error I was getting:
Traceback (most recent call last):
File "C:/xxx/solver.py", line 7, in <module>
import matplotlib
File "C:\Users\xxx\Anaconda2\lib\site-packages\matplotlib\__init__.py", line 129, in <module>
from six.moves.urllib.request import urlopen
ImportError: cannot import name urlopen
Here is the solution I used to fix this issue. It took me a while to figure this out and I couldn't find any references online that helped me, so I am posting the solution here.
I replaced the offending line in matplotlib/init.py
from six.moves.urllib.request import urlopen
with:
from urllib.request import urlopen
which allowed me to see the real error:
import socket
File "C:\PROJECTS\xxx\socket.py", line 7, in <module>
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'AF_INET'
So the problem was that I had named one of my modules "socket.py" and this was causing an error, which was masked by the six.moves importing mechanism. This file was stacked fairly deep in my project tree, but it happened to be at the same level as the script I was trying to run, which is presumably why it was being imported at the root level.
I was using PyCharm on windows for all of this.
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 6 years ago.
I have a Python script that uses requests. It worked fine for a long time. Now out of the blue I get the following error. I tried reinstalling requests but that didn't fix it. The only thing I can think of that caused the error is I have been running a Django development server, so maybe I got hacked? Please help.
code:
import requests
...
error:
Traceback (most recent call last):
File "myfile.py", line 1, in <module>
import requests
File "/Users/myuser/.virtualenvs/mysite/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/Users/myuser/.virtualenvs/mysite/lib/python2.7/site-packages/requests/utils.py", line 12, in <module>
import cgi
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cgi.py", line 50, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
You have masked the built-in library module with a local file named random.py. Rename that file.
Python looks up modules to import along a path, and if you put a module in a location that's looked at before the standard library, you can end up masking a built-in like you did here.