When a KEY contains spaces, it triggers an h11._util.LocalProtocolError: Illegal header value. While handling this exception, the openai library rethrows it as openai.APIConnectionError: Connection error. This misleads users into thinking there is a network connection issue when, in reality, the problem lies with the formatting of the KEY.
Suggested Enhancement
To prevent this misinterpretation and avoid such exceptions, it would be beneficial to implement a pre-check that trims leading and trailing spaces from the KEY before any operations are performed. This simple preprocessing step could save users from encountering misleading errors and ensure more accurate error handling.
Rationale
Trimming spaces from the KEY not only aligns with standard best practices for handling user input but also enhances the user experience by reducing the occurrence of confusing errors. This adjustment would make the error messages more relevant and helpful to users, thereby improving overall reliability and trust in the library.
Issue Description
When a KEY contains spaces, it triggers an
h11._util.LocalProtocolError: Illegal header value
. While handling this exception, the openai library rethrows it asopenai.APIConnectionError: Connection error.
This misleads users into thinking there is a network connection issue when, in reality, the problem lies with the formatting of the KEY.Suggested Enhancement
To prevent this misinterpretation and avoid such exceptions, it would be beneficial to implement a pre-check that trims leading and trailing spaces from the KEY before any operations are performed. This simple preprocessing step could save users from encountering misleading errors and ensure more accurate error handling.
Rationale
Trimming spaces from the KEY not only aligns with standard best practices for handling user input but also enhances the user experience by reducing the occurrence of confusing errors. This adjustment would make the error messages more relevant and helpful to users, thereby improving overall reliability and trust in the library.