我正在尝试使用discord.py并通过代理来运行discord机器人。 discordpy doc on this在这个主题上非常稀缺,并且不是最新的aiohttp implementation.
discordpy doc基本上说要使用ProxyConnector,并在创建客户端时将其作为参数传递。 但是在aiohttp中,不建议使用这种方式,而建议使用client.ClientSession()。get。问题是,client.ClientSession()。get要求我提供一个URL。
无论如何,我也尝试使用ProxyConnector,但是当我最终运行漫游器时(无法连接到不和谐的API),它不起作用。我不确定这有什么问题,因为代理本身可以与任何其他HTTPS服务一起正常工作。
推荐代码
conn = client.ClientSession().get(proxy='<proxy_url>', proxy_auth=BasicAuth(<proxy_auth>))
self.client = discord.Client(connector=conn)
不推荐使用的代码
conn = ProxyConnector(proxy='<proxy_url>', proxy_auth=BasicAuth(<proxy_auth>))
self.client = discord.Client(connector=conn)
追踪
Traceback (most recent call last):
File "C:/Users/airiau/PycharmProjects/pronostics/main.py", line 50, in <module>
main()
File "C:/Users/airiau/PycharmProjects/pronostics/main.py", line 46, in main
bot.run(config['token'])
File "C:\Users\airiau\PycharmProjects\pronostics\sample\DiscordBot.py", line 352, in run
self.client.run(self.token)
File "C:\Users\airiau\venv-3.6\lib\site-packages\discord\client.py", line 519, in run
self.loop.run_until_complete(self.start(*args, **kwargs))
File "C:\Program Files (x86)\Python36-32\lib\asyncio\base_events.py", line 468, in run_until_complete
return future.result()
File "C:\Users\airiau\venv-3.6\lib\site-packages\discord\client.py", line 491, in start
yield from self.connect()
File "C:\Users\airiau\venv-3.6\lib\site-packages\discord\client.py", line 444, in connect
self.ws = yield from DiscordWebSocket.from_client(self)
File "C:\Users\airiau\venv-3.6\lib\site-packages\discord\gateway.py", line 207, in from_client
timeout=60, loop=client.loop)
File "C:\Program Files (x86)\Python36-32\lib\asyncio\tasks.py", line 358, in wait_for
return fut.result()
File "C:\Users\airiau\venv-3.6\lib\site-packages\discord\gateway.py", line 65, in _ensure_coroutine_connect
ws = yield from websockets.connect(gateway, loop=loop, klass=klass)
File "C:\Users\airiau\venv-3.6\lib\site-packages\websockets\py35\client.py", line 19, in __await__
return (yield from self.client)
File "C:\Users\airiau\venv-3.6\lib\site-packages\websockets\client.py", line 210, in connect
factory, wsuri.host, wsuri.port, **kwds)
File "C:\Program Files (x86)\Python36-32\lib\asyncio\base_events.py", line 787, in create_connection
', '.join(str(exc) for exc in exceptions)))
OSError: Multiple exceptions: [Errno 10060] Connect call failed ('104.16.59.37', 443), [Errno 10060] Connect call failed ('104.16.60.37', 443)
答案 0 :(得分:1)
通过不断的研究,我发现了这个link并给出了以下答案:
discord.py使用的WebSocket似乎不支持HTTP 代理。这将与HTTPS完美配合,但是由于 代理是HTTP,但不是。这意味着,无需重写 具有HTTP代理支持的discord.py(通过使用websocket-client 例如,它支持HTTP代理),我们可能不走运。
似乎不可能完全做到这一点。