R
R
RaymanPy2019-01-23 18:55:45
Python
RaymanPy, 2019-01-23 18:55:45

How to use Proxy in TelegramBot?

There was a problem with starting the bot using Proxy:
I found 2 options for using Proxy in PyTelegramBotApi on the Internet:
1) http proxy

from telebot import apihelper
apihelper.proxy = {'http':'http://10.10.1.10:3128'}

When using this method, the following error occurs:
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot601452123:AAFiRXuFyHcoNdOsOI2ty9NXCPgx-3n14Uo/getUpdates?offset=1&timeout=123 (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),))
[Finished in 2.4s]

There is also a method using SOCKS5
apihelper.proxy = {'https':'socks5://userproxy:[email protected]_address:port'}

But it doesn't work either:
requests.exceptions.ConnectTimeout: SOCKSHTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot601452123:AAFiRXuFyHcoNdOsOI2ty9NXCPgx-3n14Uo/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x0000000004B28A20>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))
[Finished in 6.9s]

These methods are taken from the documentation. All modules have been updated.
2) Method using Socket
ip = 'ip'  # change your proxy's ip
port = port # change your proxy's port
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, port)
socket.socket = socks.socksocket

After which the local database (Mysql) does not work.
sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) 2003: Can't connect to MySQL server on 'localhost:3306' (Socket error: 0x03: Network unreachable) (Background on this error at: http://sqlalche.me/e/rvf5)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ItNoN, 2019-01-26
@RaymanPy

requests.exceptions.SSLError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot601452123:AAFiRXuFyHcoNdOsOI2ty9NXCPgx-3n14Uo/getUpdates?offset=1&timeout=123 (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),))
[Finished in 2.4s]

Says you need an SSL certificate.
Try to use working proxies with https protocol
from telebot import apihelper
apihelper.proxy = {'https':'https://88.204.154.155:8080''}

K
KOSMOS31, 2019-02-10
@KOSMOS31

Where should all this be written? what file is executable?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question