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
Related
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
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
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
I tried to import nltk library in my python code(Mac OS). and i get this error message. is there a specific nltk software i should install? or what the right command to write in the terminal?
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/Library/Python/2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/Library/Python/2.7/site-packages/nltk/chunk/api.py", line 15, in <module>
from nltk.chunk.util import ChunkScore
File "/Library/Python/2.7/site-packages/nltk/chunk/util.py", line 13, in <module>
from nltk.tag.mapping import map_tag
File "/Library/Python/2.7/site-packages/nltk/tag/__init__.py", line 63, in <module>
from nltk.tag.sequential import (SequentialBackoffTagger, ContextTagger,
File "/Library/Python/2.7/site-packages/nltk/tag/sequential.py", line 25, in <module>
from nltk.classify import NaiveBayesClassifier
File "/Library/Python/2.7/site-packages/nltk/classify/__init__.py", line 98, in <module>
from nltk.classify.textcat import TextCat
File "/Library/Python/2.7/site-packages/nltk/classify/textcat.py", line 47, in <module>
import regex as re
File "/Library/Python/2.7/site-packages/regex.py", line 672, in <module>
_pattern_type = type(_compile("", 0, {}))
File "/Library/Python/2.7/site-packages/regex.py", line 425, in _compile
pattern_locale = _getlocale()[1]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 562, in getlocale
return _parse_localename(localename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
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