N
N
NOblo2020-06-17 21:15:37
Python
NOblo, 2020-06-17 21:15:37

How to use proxy for tg bot?

Where and how to write it? How to add a proxy to the code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
origami1024, 2020-06-18
@NOblo

Using proxies in libs where you can send data is usually done by specifying the address in the parameter in the correct format, here is an example for requests:

import requests
proxies = {"https": "socks4://212.200.118.98:1080"}
...
resp = requests.post(tg_url, files=files, data=data, proxies=proxies)

You can get free proxies here:
free-proxy.cz/en/proxylist/port/1080/ping
Here is a complete example of sending a picture to a group:
import requests
proxies = {"https": "socks4://212.200.118.98:1080"} #Сербская прокся, отправляет через раз
tg_token = 'xxxxxxxxxxx'
tg_url = "https://api.telegram.org/bot" + tg_token + "/sendPhoto"
tg_chat_id = "@groupity1"

caption = 'yyyyyy yyyy yyyy'
files = {'photo': open('d://photo1.png', 'rb')}
data = {'chat_id' : tg_chat_id, 'caption': caption}

resp = requests.post(tg_url, files=files, data=data, proxies=proxies)
print(resp)

S
soremix, 2020-06-17
@SoreMix

What are you doing it on?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question