如何使用 tor 从电报 api 获取请求?

How to get request from telegram api use tor?

我的国家,telegram被屏蔽了,所以我尝试通过tor访问,ip变了,无法连接到telegram api .

import requests

proxies = {
    'http': 'socks5://127.0.0.1:9150',
    'https': 'socks5://127.0.0.1:9150'
}

url = "https://api.telegram.org/"
url_ip = "http://httpbin.org/ip"

def get_updates_json(request):  
    response = requests.get(request, proxies=proxies, verify=False)
    return response

print(get_updates_json(url_ip).text)
print(get_updates_json(url).text)

输出如下错误信息

SOCKSHTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1051)')))

导入请求

代理 = { 'http': 'socks5h://127.0.0.1:9150', 'https': 'socks5h://127.0.0.1:9150' }

url = "https://api.telegram.org/" url_ip = "http://httpbin.org/ip"

def get_updates_json(请求):
响应 = requests.get(请求,代理=代理,验证=假) return 回应

print(get_updates_json(url_ip).text) 打印(get_updates_json(url).text)