Image Request to DALL-E Failing With Server Disconnected

Hey All,

I have suddenly encountered an issue with my API request to DALL-E suddenly throwing a “Server Disconnected” when requesting anything.

It was working find maybe 2 days ago and since then it constantly disconnects

async def generate_image(userInput):
        logger = logging.getLogger(__name__)
        logger.debug("Generating image with input: %s", userInput)
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {OPENAI_KEY}'
        data = {
            'model': 'dall-e-3',
            'prompt': userInput,
            'size': '1024x1024',
            'quality': 'hd',
            'n': 1

            async with aiohttp.ClientSession() as session:
                async with'[https call here to/v1/images/generations]', headers=headers, json=data) as resp:
                    response_data = await resp.json()
                    logger.debug("Response data: %s", response_data)
                    if resp.status == 200:
                        image_url = response_data['data'][0]['url']
              "Image URL: %s", image_url)
                        return image_url
                        logger.error("Failed to generate image. Status: %s, Data: %s", resp.status, response_data)
                        return None
        except Exception as e:
            logger.exception("An error occurred while generating the image: %s", e)
            return None

and the logging returned from making the subsequent request:

> Request: Flower
> DEBUG:NetworkAdapters.OpenAINetworkAdapter:Generating image with input: Flower
> ERROR:NetworkAdapters.OpenAINetworkAdapter:An error occurred while generating the image: Server disconnected
> Traceback (most recent call last):
>   File C:\Users\...\NetworkAdapters\", line 109, in generate_image
>     async with'', headers=headers, json=data) as resp:
>   File C:\Users\...\Python\Lib\site-packages\aiohttp\", line 1141, in __aenter__
>     self._resp = await self._coro
>                  ^^^^^^^^^^^^^^^^
>   File "C:\Users\...\Python\Lib\site-packages\aiohttp\", line 560, in _request
>     await resp.start(conn)
>   File "C:\Users\...\Python\Lib\site-packages\aiohttp\", line 899, in start
>     message, payload = await  # type: ignore[union-attr]
>                        ^^^^^^^^^^^^^^^^^^^^^
>   File "C:\Users\...\Python\Lib\site-packages\aiohttp\", line 616, in read
>     await self._waiter
> aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected
> Response: None

I’m posting this mostly because I am totally baffled as to what changed. I have a request using slash commands (fails) and prefix commands (fails) both of which use the request above and fails with server disconnected everytime

After hours of debugging this issue, I have found two potential solutions to this problem.

In VS code I had a library asyncio I removed as it claimed the library was unused. However I think it’s necessary to use the aiottp library. I can only assume asyncio is used by aiohttp.

Interestingly enough I realized connecting to a VPN caused a very similar issue in terms of “server disconnect” - So ensure you are not connected to VPN unless purposefully doing so.