【问题标题】:Error When Running my Discord Bot on Python Anywhere在 Python Anywhere 上运行我的 Discord Bot 时出错
【发布时间】:2019-04-27 16:05:04
【问题描述】:

我使用 Python 3.6 制作了一个 Discord Bot。它在我的计算机上运行时运行良好,但当我在 PythonAnywhere 上运行它时,我收到了这条消息。我安装了 Discord.py 和所有必要的模块。请帮忙。我不太擅长复杂的编程谈话,也不擅长网络谈话,所以请尽可能简单地回答。这个问题是否只发生在 PythonAnywhere 或所有远程托管站点上?

01:42 ~ $ python3.6 MyCoolBot.py
Traceback (most recent call last):
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 601, in _create_direc
t_connection
    local_addr=self._local_addr)
  File "/usr/lib/python3.6/asyncio/base_events.py", line 778, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.6/asyncio/base_events.py", line 765, in create_connection
    yield from self.sock_connect(sock, address)
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 450, in sock_connect
    return (yield from fut)
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 480, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 111] Connect call failed ('104.16.58.5', 443)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 304, in connect
    yield from self._create_connection(req)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 578, in _create_conne
ction
    transport, proto = yield from self._create_direct_connection(req)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 624, in _create_direc
t_connection
    (req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 111] Can not connect to discordapp.com:443 [Connect call failed ('104.16.
58.5', 443)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "MyCoolBot.py", line 39, in <module>
    client.run('MY_BOT_TOKEN')
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/discord/client.py", line 519, in run
    self.loop.run_until_complete(self.start(*args, **kwargs))
  File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
    return future.result()
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/discord/client.py", line 490, in start
    yield from self.login(*args, **kwargs)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/discord/client.py", line 416, in login
    yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/discord/client.py", line 346, in _login_1
    data = yield from self.http.static_login(token, bot=is_bot)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/discord/http.py", line 258, in static_login
    data = yield from self.request(Route('GET', '/users/@me'))
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/discord/http.py", line 137, in request
    r = yield from self.session.request(method, url, **kwargs)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/client.py", line 555, in __iter__
    resp = yield from self._coro
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/client.py", line 198, in _request
    conn = yield from self._connector.connect(req)
  File "/home/CompuGenius/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 314, in connect
    .format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 111] Cannot connect to host discordapp.com:443 ssl:True [Can not connect to discordapp.com:443 [Connect call failed ('104.16.58.5', 443)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f4b25d81be0>

【问题讨论】:

  • 这是因为 PythonAnywhere 需要 aiohttp websocket 不支持的代理。他们的论坛上有一个关于它的帖子:pythonanywhere.com/forums/topic/7384
  • 您刚刚泄露了您的机器人令牌。我将编辑您的问题以不再拥有它,但您应该立即重新生成您的令牌。转到您的机器人页面discordapp.com/developers/applications,找到您从哪里开始提取令牌,并点击“重新生成”。
  • @c.berger 为什么会有这样的问题?它是否允许其他人访问?因为我的机器人变了!
  • @CompuGenius 一个不道德的用户可以用它来运行他们自己的应用程序作为你的机器人,是的。
  • 谢谢,我删除了所有实例,所以它们不会再有问题了

标签: python bots discord discord.py pythonanywhere


【解决方案1】:

这是因为 PythonAnywhere 需要 aiohttp websocket 不支持的代理。他们的论坛上有一个关于它的帖子:https://www.pythonanywhere.com/forums/topic/7384/(参见上面@Patrick Haugh 的评论)

【讨论】:

    猜你喜欢
    • 2022-11-27
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2019-06-08
    • 2018-07-29
    • 1970-01-01
    • 2020-05-28
    相关资源
    最近更新 更多