OpenAI error not being logged

Hi,

I am using python logging module to log errors. I have a try-except block in my code where I catch OpenAI API call errors in there and log them into a script. The logging works fine when I test it with different messages, etc. However, it doesn’t log the OpenAI error, you can see in below.

try:
pass
except Exception as e:
logger.error(f"“” This is the OpenAI error: {e} “”")
print(e)

If I print out the error, the output is:
Error code: 404 - {‘error’: {‘message’: “No assistant found with id ‘asst_i2oWqFqSLXXxlS1YR4LcjKzGhE’.”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

Note that I am not looking for ways to fix the error, but rather, I am looking for a way to be able to log that error! I would appreciate your help with this. Thank you.

PS - indentation in the code is correct, it just doesn’t work in this forum.

It works fine for me. I think this is a logging configuration problem rather than the API.

2024-05-15 18:58:59 - Assistants - INFO - Error running thread: Error code: 404 - {‘error’: {‘message’: “No assistant found with id ‘1’.”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

1 Like