A
A
Artur Galyaev2018-08-14 10:50:17
Python
Artur Galyaev, 2018-08-14 10:50:17

Error when starting a telegram bot in python. How to decide?

The code:

# art

import telebot

bot = telebot.TeleBot("здесь токен")

bot.send_message(394970516, "text")

Error:
C:\Users\1\AppData\Local\Programs\Python\Python35\python.exe C:/Users/1/PycharmProjects/untitled2/art.py
Traceback (most recent call last):
File "C:\Users \1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\1\AppData\Local\Programs\ Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site -packages\urllib3\connectionpool.py", line 849, in _validate_conn
conn.connect()
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connection.py ",line 356, in connect
ssl_context=context)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\ssl_.py", line 359, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 376, in wrap_socket
_context=self)
File "C:\Users\1\AppData\ Local\Programs\Python\Python35\lib\ssl.py", line 747, in __init__
self.do_handshake()
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\ssl.py" , line 983, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] The remote host forcibly terminated an existing connection
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\1\AppData\Local\Programs\Python\Python35\ lib\site-packages\requests\adapters.py", line 445, in send
timeout=timeout
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool. py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\retry. py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C: \Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\1\AppData\Local\ Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib \site-packages\urllib3\connectionpool.py", line 849, in _validate_conn
conn.connect()
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connection .py", line 356, in connect
ssl_context=context)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\util\ssl_.py", line 359, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 376, in wrap_socket
_context=self)
File "C:\Users\1\AppData\ Local\Programs\Python\Python35\lib\ssl.py", line 747, in __init__
self.do_handshake()
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\ssl.py" , line 983, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'Remote host forcibly aborted existing connection', None, 10054, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last ):
File "C:/Users/1/PycharmProjects/untitled2/art.py", line 7, in
bot.send_message(394970516, "text")
File "C:\Users\1\AppData\Local\Programs\Python \Python35\lib\telebot\__init__.py", line 480, in send_message
reply_markup, parse_mode, disable_notification))
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\telebot\apihelper.py ", line 140, in send_message
return _make_request(token, method_url,params=payload, method='post')
File "C:\Users\1\AppData\Local\Programs\Python\Python35\lib\telebot\apihelper.py", line 54, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "C:\ Users\1\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users \1\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\Users\ 1\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\adapters.py", line 495, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'Remote host forcibly aborted existing connection', None, 10054, None))
Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
igorzakhar, 2018-08-14
@art5455

As Pavel Denisov already wrote here , the problem is blocking telegram on the territory of the Russian Federation. You can try to use VPS in a foreign data center. I, in order to play around with the telegram bot API, used the openshift platform ( https://www.openshift.com/ ), there is a free use option. How to "hide" the token in an environment variable when using openshit can be read here: How to hide the telegram bot token when the repository is open on github and hosted on openshift?

A
AlexSn2020, 2020-07-09
@AlexSn2020

Hello everyone) Faced the same problem, only the cart is already unlocked in Russia)

S
Saer22, 2020-01-11
@Saer22

Connect through a proxy.
For example:
import telebot
from telebot import apihelper
access_token = '***'
apihelper.proxy = {'https': ' https://85.132.71.82:3128 '}

P
Pan Propan, 2018-08-14
@mgis

Update Python to 3.6

X
xozzslip, 2019-05-13
@xozzslip

cart is blocked. put vpn

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question