Support http proxy. (#93)

 支持使用 http 代理。
This commit is contained in:
Xtao_dada 2021-06-19 21:53:03 +08:00 committed by GitHub
parent cb7697b895
commit 3552ebf0be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View File

@ -51,9 +51,11 @@ height: "1080"
background: "#101010"
margin: "20"
#socks5 or MTProto
#socks5 or http or MTProto
proxy_addr: ""
proxy_port: ""
http_addr: ""
http_port: ""
mtp_addr: ""
mtp_port: ""
mtp_secret: ""

View File

@ -111,12 +111,16 @@ api_hash = config['api_hash']
try:
proxy_addr = config['proxy_addr'].strip()
proxy_port = config['proxy_port'].strip()
http_addr = config['http_addr'].strip()
http_port = config['http_port'].strip()
mtp_addr = config['mtp_addr'].strip()
mtp_port = config['mtp_port'].strip()
mtp_secret = config['mtp_secret'].strip()
except:
proxy_addr = ''
proxy_port = ''
http_addr = ''
http_port = ''
mtp_addr = ''
mtp_port = ''
mtp_secret = ''
@ -140,11 +144,20 @@ if api_key is None or api_hash is None:
if not proxy_addr == '' and not proxy_port == '':
try:
import socks
import python_socks
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True,
proxy=(python_socks.ProxyType.SOCKS5, proxy_addr, int(proxy_port)))
except:
pass
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True,
proxy=(socks.SOCKS5, proxy_addr, int(proxy_port)))
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True)
elif not http_addr == '' and not http_port == '':
try:
import python_socks
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True,
proxy=(python_socks.ProxyType.HTTP, proxy_addr, int(proxy_port)))
except:
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True)
elif not mtp_addr == '' and not mtp_port == '' and not mtp_secret == '':
from telethon import connection

View File

@ -32,7 +32,7 @@ Flask-Bcrypt>=0.7.1
Flask-WTF>=0.15.1
WTForms>=2.3.3
cheroot>=8.5.2
PySocks>=1.7.1
python-socks[asyncio]>=1.2.4
certifi>=2021.5.30
magic_google>=0.2.9
sentry-sdk>=1.1.0