Python aiohttp "[Errno 104] Connection reset by peer" on Roblox domains

I’m trying to make requests to the Roblox cloud API (UserRestrictions) in Python using the aiohttp library. My code was working perfectly until today when it suddenly stopped with no changes to the environment.

The error in question is aiohttp.client_exceptions.ClientOSError: [Errno 104] Connection reset by peer. I made a test script to see if it was related to the headers I was using, but it seems to be affecting requests to any roblox.com domain. I’ve restarted the system (ubuntu 24.04) numerous times, cleared the DNS cache and reinstalled the packages, but the issue persists. Running curl https://apis.roblox.com/ works completely fine, so I don’t think it’s a rate limit.

I’m unable to replicate this error on other systems.

import asyncio, aiohttp

async def run():
    async with aiohttp.ClientSession() as Session:
        Request = await Session.get("https://google.com/") # Doesn't error

        print(await Request.text())    

        Request = await Session.get("https://apis.roblox.com/") # Does error

        print(await Request.text())    

asyncio.run(run())
Full Error
Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/selector_events.py", line 988, in _read_ready__get_buffer
    nbytes = self._sock.recv_into(buf)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./env/lib/python3.12/site-packages/discord/client.py", line 481, in _run_event
    await coro(*args, **kwargs)
  File "./main.py", line 69, in on_ready
    Request = await Session.get(
              ^^^^^^^^^^^^^^^^^^
  File "./env/lib/python3.12/site-packages/aiohttp/client.py", line 770, in _request
    resp = await handler(req)
           ^^^^^^^^^^^^^^^^^^
  File "./env/lib/python3.12/site-packages/aiohttp/client.py", line 748, in _connect_and_send_request
    await resp.start(conn)
  File "./env/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 532, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "./env/lib/python3.12/site-packages/aiohttp/streams.py", line 672, in read
    await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 104] Connection reset by peer

ANY help will be HEAVILY appreciated. If Roblox Devforum isn’t exactly the right place to post this, please point me in the right direction. I’ve been at this for multiple hours🙏

1 Like

Does it happen with the requests library?

1 Like

Yes, it works with requests. However, this is for a discord.py bot, so I need an async HTTP library.

Can you put the requesting code into asyncio.to_thread and use requests with that? Or make it threaded in any other way

About the aiohttp errors you could try using a VPN, I tried your sample code on Arch and it worked fine

1 Like

This isnt right fully, try again later.

Same issue here, looking for a solution

As of today, I was able to fix it by adding this code.

import asyncio, aiohttp, ssl
ssl_context = ssl.create_default_context()

async def run():
    aiohttp.TCPConnector.__init__.__kwdefaults__["ssl"] = ssl_context # Fix

    async with aiohttp.ClientSession() as Session:
        Request = await Session.get("https://apis.roblox.com/")

        print(await Request.text())    

asyncio.run(run())
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.