Handle OpenAIErrors created with 'str' json_body#356
Merged
hallacy merged 1 commit intoopenai:mainfrom Mar 29, 2023
Merged
Conversation
`api_requestor.py` recently started respecting `text/plain` response `Content-Type`s. Azure OpenAI can sometimes return errors with that Content-Type that are still JSON strings with error info, which can break OpenAIErrors default behavior of checking for `error` being `in` the supplied `json_body`. Classic Python, `in` works for `dict` or `str` but `json_body["error"]` will only work if `json_body` is a `dict`. This is the minimal fix to now throw KeyError and let the unparsed json_body + message bubble up in the OpenAIError.
Contributor
Author
|
Cheers @hallacy! |
Collaborator
|
0.27.3 just got released today! |
davedittrich
pushed a commit
to davedittrich/openai-python
that referenced
this pull request
Nov 14, 2023
`api_requestor.py` recently started respecting `text/plain` response `Content-Type`s. Azure OpenAI can sometimes return errors with that Content-Type that are still JSON strings with error info, which can break OpenAIErrors default behavior of checking for `error` being `in` the supplied `json_body`. Classic Python, `in` works for `dict` or `str` but `json_body["error"]` will only work if `json_body` is a `dict`. This is the minimal fix to now throw KeyError and let the unparsed json_body + message bubble up in the OpenAIError.
cgayapr
pushed a commit
to cgayapr/openai-python
that referenced
this pull request
Dec 14, 2024
`api_requestor.py` recently started respecting `text/plain` response `Content-Type`s. Azure OpenAI can sometimes return errors with that Content-Type that are still JSON strings with error info, which can break OpenAIErrors default behavior of checking for `error` being `in` the supplied `json_body`. Classic Python, `in` works for `dict` or `str` but `json_body["error"]` will only work if `json_body` is a `dict`. This is the minimal fix to now throw KeyError and let the unparsed json_body + message bubble up in the OpenAIError.
safa0
pushed a commit
to safa0/openai-agents-python
that referenced
this pull request
Apr 27, 2025
Towards openai#345 ## Summary: Using a `dict` or `Mapping` isn't strict-mode compliant. But we were checking for the literal `True` whereas the value can also be an array, for example. Fix that. ## Test Plan: Unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
api_requestor.pyrecently started respectingtext/plainresponseContent-Types. Azure OpenAI can sometimes return errors with that Content-Type that are still JSON strings with error info, which can break OpenAIErrors default behavior of checking forerrorbeinginthe suppliedjson_body. Classic Python,inworks fordictorstrbutjson_body["error"]will only work ifjson_bodyis adict.This is the minimal fix to not throw KeyError and let the unparsed json_body + message bubble up in the OpenAIError.