我想对python代码隐藏我的代理。所以我试着用problem解析器来做这件事,但是我有问题。
cpass = configparser.RawConfigParser()
cpass.read('config.data')
try:
api_id = cpass['cred']['id']
api_hash = cpass['cred']['hash']
phone = cpass['cred']['phone']
proxy = cpass['cred']['proxy']
client = TelegramClient(phone, api_id, api_hash, proxy=proxy)因此,当我尝试开始我的会话时,我错了:TypeError:未知格式的代理:我的代理设置在文件config.data中,例如:=‘socks5 5’,'185.183.162.152',8030,True,'82DOLD','DTANSF‘(这是假代理)。不要尝试使用)
发布于 2022-07-21 17:55:21
如果您需要使用代理访问电报,则需要:
python-socks[asyncio]
PySocks参数proxy_type的允许值是:
For Python <= 3.5:
socks.SOCKS5或'socks5'socks.SOCKS4或'socks4'socks.HTTP或'http'For Python >= 3.6:
所有above
python_socks.ProxyType.SOCKS5
python_socks.ProxyType.SOCKS4
python_socks.ProxyType.HTTP的
例>= 3.6
pip3 install "python-socks[asyncio]"from python_socks import ProxyType
my_proxy = {
'proxy_type': ProxyType.SOCKS5, # (mandatory) protocol to use (see above)
'addr': '1.1.1.1', # (mandatory) proxy IP address
'port': 5555, # (mandatory) proxy port number
'username': 'foo', # (optional) username if the proxy requires auth
'password': 'bar', # (optional) password if the proxy requires auth
'rdns': True # (optional) whether to use remote or local resolve, default remote
}
TelegramClient('anon', api_id, api_hash, proxy=my_proxy)例<= 3.5
pip3 install PySocksimport socks
my_proxy = (socks.SOCKS5, '1.1.1.1', 5555, True, 'foo', 'bar')
TelegramClient('anon', api_id, api_hash, proxy=my_proxy)https://stackoverflow.com/questions/73035492
复制相似问题