1

I work through a corporate network, there is a need to write a bot telegram, I tried various libraries (`` telebot, telepot, telegram, airogram ''). Everywhere I come across the problem of access through a corporate proxy. Now I stopped at telebot, slipped a proxy, now there is an error with certificate verification. Tried using http, https, socks5, socks5h, socks4 with no success.

import telebot
import json
from telebot import apihelper

with open ('params.json', 'r', encoding = 'utf-8') as f:
    data = json.load (f)
username = data ['username']
password = data ['password']
access_token_tg = data ['access_token_tg']
bot = telebot.TeleBot (access_token_tg)
apihelper.proxy = {'https': f'https: // {username}: {password} @ 10.0.18.139: 3131'}
print (bot.get_me ())

I get an error in response.

requests.exceptions.SSLError: HTTPSConnectionPool (host = 'api.telegram.org', port = 443): Max retries exceeded with url: / my token here / getMe (Caused by SSLError (SSLCertVerificationError (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c: 1123) ')))

I tried to communicate via request with the cart, I was able to connect, only after disabling the ssl check `` session.verify = False ''. But it is very problematic to write through requests, in fact, there are a lot of libraries for this.

import pprint
from requests.auth import HTTPProxyAuth
import urllib3
import requests
import json

# read config
with open ('params.json', 'r', encoding = 'utf-8') as f:
    data = json.load (f)
username = data ['username']
password = data ['password']
access_token_tg = data ['access_token_tg']

# create a session to work with the bot
auth = HTTPProxyAuth (username, password)
proxies = {'https': f'https: // {username}: {password} @ 10.0.18.139: 3131'}
session = requests.Session ()
session.proxies = proxies
session.auth = auth

# chopped off the verification of the certificate and warning
urllib3.disable_warnings ()
session.verify = False

MAIN_URL = f'https: //api.telegram.org/bot {access_token_tg} '
res = session.post (f '{MAIN_URL} / getMe'). json ()
pprint.pprint (res)
This is how it works.

I ask you to help me figure it out, or maybe I can advise another manual or bibla, I have been fighting with this for 2 weeks.
Vadim
  • 11
  • 1

0 Answers0