Getting AttributeError : module ‘openai’ has no attribute ‘error’

Sorry, I found the answer, wasn’t reading carefully enough. From the official GitHub under Handling Errors:

import openai
from openai import OpenAI

client = OpenAI()

try:
    client.fine_tunes.create(
        training_file="file-XGinujblHPwGLSztz8cPS8XY",
    )
except openai.APIConnectionError as e:
    print("The server could not be reached")
    print(e.__cause__)  # an underlying Exception, likely raised within httpx.
except openai.RateLimitError as e:
    print("A 429 status code was received; we should back off a bit.")
except openai.APIStatusError as e:
    print("Another non-200-range status code was received")
    print(e.status_code)
    print(e.response)

So you have to import openai and OpenAI, then use openai without the .error in the except statements. Kind of messy, but as long as it works I guess.

2 Likes