when importing requests in pycharm, Import error occurs - python

When importing requests, the following error message occurs.
Traceback (most recent call last):
File "C:/Users/moter/PycharmProjects/compsci/alarm_project/get_events.py", line 1, in <module>
import requests
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\packages\six.py", line 199, in load_module
mod = mod._resolve()
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\packages\six.py", line 113, in _resolve
return _import_module(self.mod)
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\email\utils.py", line 33, in <module>
from email._parseaddr import quote
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\email\_parseaddr.py", line 16, in <module>
import time, calendar
File "C:\Users\moter\PycharmProjects\compsci\alarm_project\calendar.py", line 1, in <module>
from O365 import Account
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\O365\__init__.py", line 8, in <module>
from .account import Account
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\O365\account.py", line 1, in <module>
from .connection import Connection, Protocol, MSGraphProtocol
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\O365\connection.py", line 9, in <module>
from requests import Session
ImportError: cannot import name 'Session' from 'requests' (C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\__init__.py)
CODE:
import requests
import sys
print(sys.path)
r = requests.get("https://openweathermap.org/")
print(r.status_code)
I have updated requests from both pip and pycharm itself. Furthermore, I have tried different python versions and the error persists. The error does not occur in IDLE however, but still occurs in other IDEs.

Note these lines in your traceback:
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\email\_parseaddr.py", line 16, in <module>
import time, calendar
File "C:\Users\moter\PycharmProjects\compsci\alarm_project\calendar.py", line 1, in <module>
from O365 import Account
You have a file named calendar.py which conflicts with something that the email module is trying to import. Your file calendar.py does then go on to import something from O365 which ends up trying to import Session from requests:
from O365 import Account
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\O365\__init__.py", line 8, in <module>
from .account import Account
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\O365\account.py", line 1, in <module>
from .connection import Connection, Protocol, MSGraphProtocol
File "C:\Users\moter\AppData\Local\Programs\Python\Python37\lib\site-packages\O365\connection.py", line 9, in <module>
from requests import Session
Which ends up being a circular import, caused by the conflicting filename. So simply rename your calendar.py, e.g. to mycalendar.py and your issue should be solved

Related

ImportError: cannot import name 'request'

I am a windows user. I used the command pip install requests to have requests installed, and I also typedpip install urllib3 to have urllib3 installed. However, I am not able to run this code: from requests import request. I got a error like this:
Traceback (most recent call last):
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\__init__.py", line 27, in <module>
from . import urllib3
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "D:\Python\lib\http\client.py", line 71, in <module>
import email.parser
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
ImportError: cannot import name 'request'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\__init__.py", line 29, in <module>
import urllib3
File "D:\Python\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "D:\Python\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "D:\Python\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "D:\Python\lib\http\client.py", line 71, in <module>
import email.parser
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
ImportError: cannot import name 'request'
I saw a lot of answers saying that there is another file with duplicate name that occur this error, however, I searched through the fold, I did found one. I even reinstalled my python, but I still got this error. Please help me.
Try using
from requests import Request
instead of
from requests import request

ImportError: cannot import name 'multiarray' [New Edit this are good]

I have this error and I do not know how to fix it I have tried many meneras and I do not know how I created new post because the other was badly
Traceback (most recent call last):
File "run.py", line 9, in <module>
from layer import MacLayer
File "/root/MacBot/layer.py", line 5, in <module>
from app import main
File "/root/MacBot/app/main.py", line 8, in <module>
from app.yesno.yesno import YesNo
File "/root/MacBot/app/yesno/yesno.py", line 2, in <module>
import moviepy.editor as mp
File "/usr/local/lib/python3.5/dist-packages/moviepy-0.2.2.11-py3.5.egg/moviepy/editor.py", line 22, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "/usr/local/lib/python3.5/dist-packages/moviepy-0.2.2.11-py3.5.egg/moviepy/video/io/VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "/usr/local/lib/python3.5/dist-packages/moviepy-0.2.2.11-py3.5.egg/moviepy/video/VideoClip.py", line 15, in <module>
import numpy as np
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
Easiest solution is to use anaconda available from continuum.io/downloads
then you aren't messing with compiling this yourself.

Cannot import Random in Python chatbot I am creating

I want to create a chatbot using the telegram api in Python, but I get an error.
Below is my code:
import telepot, time
import urllib3
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print 'Got command: %s' % command
if command == '/hello':
bot.sendMessage(chat_id, "Hello, how are you?")
bot = telepot.Bot('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
bot.notifyOnMessage(handle)
while 1:
time.sleep(10)
The error I am getting is:
Traceback (most recent call last):
File "C:\Users\KUNTALS\workspace\ChatBot\tel_bot4.py", line 1, in <module>
import telepot, time
File "C:\Python27\lib\site-packages\telepot\__init__.py", line 259, in <module>
from . import api
File "C:\Python27\lib\site-packages\telepot\api.py", line 1, in <module>
import urllib3
File "C:\Python27\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Python27\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "C:\Python27\lib\site-packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "C:\Python27\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Python27\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Python27\lib\httplib.py", line 80, in <module>
import mimetools
File "C:\Python27\lib\mimetools.py", line 6, in <module>
import tempfile
File "C:\Python27\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random

Pass the values from multiple select list in html form using Flask

Try to run an app on local machine through virtual environment. But run into this issues related to libssl. Have libssl.1.0.0.dylib in the reference folder so I don't know why it cannot find the method. Really appreciate anyone can give me a direction.
Traceback (most recent call last):
File "app.py", line 4, in <module>
from traffic_analytics import traffic_analytics
File "/Users/zhehaozhou/Documents/Development/giq-analytics/dashboard-x/webapp/traffic_analytics.py", line 12, in <module>
from traffic import download_ga_data as ga_downloader
File "/Users/zhehaozhou/Documents/Development/giq-analytics/dashboard-x/webapp/traffic/download_ga_data.py", line 13, in <module>
from ga import GoogleAnalytics
File "/Users/zhehaozhou/Documents/Development/giq-analytics/dashboard-x/webapp/traffic/ga.py", line 8, in <module>
from apiclient import errors
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/apiclient/__init__.py", line 19, in <module>
from googleapiclient import discovery
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/googleapiclient/discovery.py", line 66, in <module>
from oauth2client.client import GoogleCredentials
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/oauth2client/client.py", line 46, in <module>
from oauth2client import crypt
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/oauth2client/crypt.py", line 40, in <module>
from OpenSSL import crypto
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/OpenSSL/rand.py", line 11, in <module>
from OpenSSL._util import (
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/OpenSSL/_util.py", line 7, in <module>
binding = Binding()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 114, in __init__
self._ensure_ffi_initialized()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 126, in _ensure_ffi_initialized
cls._modules,
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/hazmat/bindings/utils.py", line 31, in load_library_for_binding
lib = ffi.verifier.load_library()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cffi/verifier.py", line 97, in load_library
return self._load_library()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cffi/verifier.py", line 207, in _load_library
return self._vengine.load_library()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cffi/vengine_cpy.py", line 153, in load_library
raise ffiplatform.VerificationError(error)
cffi.ffiplatform.VerificationError: importing '/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_f3e4673fx399b1113.so': dlopen(/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_f3e4673fx399b1113.so, 2): Symbol not found: _SSLv2_client_method
Referenced from: /Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_f3e4673fx399b1113.so
Expected in: /usr/lib/libssl.1.0.0.dylib

Cannot import name ProtocolError [RaspberryPi, Jasper]

I had installed sphinx and Jasper on my RPI. When I'm trying to start Jasper - i got this:
Traceback (most recent call last):
File "/home/pi/jasper/jasper.py", line 14, in <module>
from client import vocabcompiler, stt, jasperpath
File "/home/pi/jasper/client/stt.py", line 6, in <module>
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python2.7/dist-packages/requests/utils.py", line 25, in <module>
from .compat import parse_http_list as _parse_list_header
File "/usr/local/lib/python2.7/dist-packages/requests/compat.py", line 7, in <module>
from .packages import charade as chardet
File "/usr/local/lib/python2.7/dist-packages/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/__init__.py", line 16, in <module>
from .connectionpool import (
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 33, in <module>
from .connection import (
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connection.py", line 41, in <module>
from .util import (
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/__init__.py", line 18, in <module>
from .retry import Retry
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/retry.py", line 4, in <module>
from ..exceptions import (
ImportError: cannot import name ProtocolError
Who can help me with this error? Thank you
you should
pip install urllib3

Categories