使用 Telethon 模块将代理连接到 Python 脚本
Connecting a proxy to a Python script using the Telethon module
我需要从 proxy.txt 文件中获取代理:
ip:port:username:password
并添加到代码中:
file = dbm_base()
api_id = int(file['api_id4'].decode())
api_hash = file['api_hash4'].decode()
client = TelegramClient('client4', api_id, api_hash, proxy=(socks.SOCKS5, 'ip', port, 'username', 'password'))#port without ''
我这样做:
with open('proxy.txt', 'r') as f:
proxys = f.readline().split(":")
file = dbm_base()
api_id = int(file['api_id4'].decode())
api_hash = file['api_hash4'].decode()
s = socks.socksocket()
client = TelegramClient('client1', api_id, api_hash, proxy=s.set_proxy(socks.HTTP, f'{proxys[0]}', int(proxys[1]), f'{proxys[2]}', f'{proxys[3]}'))
但是代理服务器没有连接到脚本。
我做错了什么,为什么代理服务器连接不上?
不确定 HTTP 代理或其他代理,但您可以非常轻松地使用 MTPROTO 代理:
server = 'firewall.firewall-gw.cam' # TODO: proxy server or ip
port = 443 # TODO: set port, normally 443
secret = 'dd00000000000000000000000000000000' # TODO: set proxy secret, normally hex encoded
connection = connection.ConnectionTcpMTProxyRandomizedIntermediate # this mode supports most proxies
client = TelegramClient('client1', api_id, api_hash, connection=connection,proxy=(server, port, secret)))
MTPROXY 可以取自 @ProxyMTProto. (Note: Its open source here)
其他 public 代理的问题是它们经常过期。
了解更多here。
我需要从 proxy.txt 文件中获取代理:
ip:port:username:password
并添加到代码中:
file = dbm_base()
api_id = int(file['api_id4'].decode())
api_hash = file['api_hash4'].decode()
client = TelegramClient('client4', api_id, api_hash, proxy=(socks.SOCKS5, 'ip', port, 'username', 'password'))#port without ''
我这样做:
with open('proxy.txt', 'r') as f:
proxys = f.readline().split(":")
file = dbm_base()
api_id = int(file['api_id4'].decode())
api_hash = file['api_hash4'].decode()
s = socks.socksocket()
client = TelegramClient('client1', api_id, api_hash, proxy=s.set_proxy(socks.HTTP, f'{proxys[0]}', int(proxys[1]), f'{proxys[2]}', f'{proxys[3]}'))
但是代理服务器没有连接到脚本。
我做错了什么,为什么代理服务器连接不上?
不确定 HTTP 代理或其他代理,但您可以非常轻松地使用 MTPROTO 代理:
server = 'firewall.firewall-gw.cam' # TODO: proxy server or ip
port = 443 # TODO: set port, normally 443
secret = 'dd00000000000000000000000000000000' # TODO: set proxy secret, normally hex encoded
connection = connection.ConnectionTcpMTProxyRandomizedIntermediate # this mode supports most proxies
client = TelegramClient('client1', api_id, api_hash, connection=connection,proxy=(server, port, secret)))
MTPROXY 可以取自 @ProxyMTProto. (Note: Its open source here)
其他 public 代理的问题是它们经常过期。
了解更多here。