openai / openai-python

The official Python library for the OpenAI API

Home Page:https://pypi.org/project/openai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Requests timing out

RaulSantanaTrejo opened this issue · comments

I am running a Python backend service using fastapi and a docker container and every once in a while all requests start timing out for no apparent reason. The same request can time out and suddenly work an hour later. The service is under development so my team is the only one currently using our keys and service. I have created a simple call with no fancy logic and using the ada model but this still times out (see code below). I get

"error.APIConnectionerror("error communicating with OpenAI")"

coming from

"requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/engines/text-ada-001/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3052475310>: Failed to establish a new connection: [Errno 110] Connection timed out'))"

Code:

def simple_call():
    openai.organization = config('ORGANIZATION')
    openai.api_key = config('API_KEY')
    print("WARNING: performing simple call")
    prompt = "Tell me a fun story to cheer me up"
    completion = openai.Completion.create(**{"engine": "text-ada-001", "max_tokens": 500, "prompt": prompt})
    response = {'generations': [{'prompt': prompt, 'question': "MOCK", 'answer': completion["choices"][0]["text"]}]}
    return response

Any advice is appreciated

Hi @RaulSantanaTrejo, thanks for the issue!

That's...odd. I don't have an immediate reason for why that's happening. We've heard occasional reports about connection issues related to docker firewalls, but not quite like this. Usually the errors are more consistent in that case.

We're probably going to need more information in order to debug this (especially your org id so we can look at the requests in question). Any chance you could forward this issue to support@openai.com? They should be able to better assist you on this issue (this is just the python interface and isn't as equipped to handle API errors)

Thank you for the quick reply! I will contact the support team and update this if the problem is not just on our end

I'm going to close out this issue. Feel free to reopen it if needed