Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Keys with Spaces Triggers Misleading Connection Error #295

Closed
runjinz opened this issue Mar 21, 2024 · 0 comments
Closed

Handling Keys with Spaces Triggers Misleading Connection Error #295

runjinz opened this issue Mar 21, 2024 · 0 comments

Comments

@runjinz
Copy link
Contributor

runjinz commented Mar 21, 2024

Issue description:

When a key contains spaces, it triggers an exception with the message h11._util.LocalProtocolError: Illegal header value. When this occurs, the OpenAI library rethrows this as an openai.APIConnectionError: Connection error., which can misleadingly suggest that the issue lies with network connectivity rather than with the key's formatting.

This has the potential to lead users down the wrong path when troubleshooting, as the real issue is related to the presence of spaces in the key. A beneficial enhancement would be to strip leading and trailing spaces from keys before they are used. Implementing a simple trim operation on keys can prevent this kind of exception from happening and improve user experience by providing more accurate error feedback.

Suggested change:

  • Implement a preprocessing step for keys that strips leading and trailing whitespace before they are used in any API requests. This can be done either within the OpenAI library where keys are handled or as a recommended practice in the documentation.

The goal of this change is to prevent Illegal header value exceptions related to key formatting and to ensure that errors thrown reflect the actual problem more accurately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant