PythonAnywhere Forums

Discord Bot problems

Hey I'm trying to host here 24h/24h a python bot for the discussion service Discord. It works on My PC. I've seen a topic in the firum talking about that so I added all the stuff about proxies. Now I still have this errors :

    Traceback (most recent call last):
  File "Bot.py", line 4, in <module>
    proxyc = aiohttp.ProxyConnector("http://proxy.server:3128")
NameError: name 'aiohttp' is not defined
17:44 ~ $ python3 Bot.py
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
    yield from self.sock_connect(sock, address)
  File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 439, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 111] Connect call failed ('104.16.60.37', 443)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "Bot.py", line 78, in <module>
    client.run('MjE4OTU4OTMxMTk4NzM4NDQy.CqKxDg.raJ-dZ9A6KI-Z2kday33Y1RTYWE')
  File "/home/Pyrrha/.local/lib/python3.5/site-packages/discord/client.py", line 487, in run
    self.loop.run_until_complete(self.start(*args, **kwargs))
  File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
    return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/home/Pyrrha/.local/lib/python3.5/site-packages/discord/client.py", line 459, in start
    yield from self.connect()
  File "/home/Pyrrha/.local/lib/python3.5/site-packages/discord/client.py", line 412, in connect
    self.ws = yield from DiscordWebSocket.from_client(self)
  File "/home/Pyrrha/.local/lib/python3.5/site-packages/discord/gateway.py", line 174, in from_client
    ws = yield from websockets.connect(gateway, loop=client.loop, klass=cls)
  File "/home/Pyrrha/.local/lib/python3.5/site-packages/websockets/py35/client.py", line 19, in __await__
    return (yield from self.client)
  File "/home/Pyrrha/.local/lib/python3.5/site-packages/websockets/client.py", line 150, in connect
    factory, wsuri.host, wsuri.port, **kwds)
  File "/usr/lib/python3.5/asyncio/base_events.py", line 704, in create_connection
    ', '.join(str(exc) for exc in exceptions)))
OSError: Multiple exceptions: [Errno 111] Connect call failed ('104.16.59.37', 443), [Errno 111] Connect call failed ('104.16.60.37', 443)
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f098867f748>

If there is no way to fix that : Is there another service which can make it work? Thx

[edited by admin: formatting]

It is because external internet access for free users are restricted to a whitelist.

We are happy to add any public api's to the whitelist if you provide us with the api's documentation showing the official api endpoint.

Otherwise, you will have to upgrade your account.

https://discordpy.readthedocs.io/en/latest/ Here's the api doc ;)

discordapp.com is already on the whitelist, but only the http API will work on PythonAnywhere, not the websockets API.

Is github okay? https://github.com/hammerandchisel/discord-api-docs

You need to use discord over their http api and not web sockets if you are a free user. The whitelist stuff for free users only pertain to http/https.

pls how do i use it over their http api and not web sockets? i do not understand pls

pls how do i use it over their http api and not web sockets? i do not understand pls