I created an API key and an assistant. Testing the keys in the OpenAPI Playground, it works perfectly well. I then ran the code as shown on the Pidog tutorial
cd ~/pidog/gpt_examples/
sudo ~/my_venv/bin/python3 gpt_dog.py --keyboard,
It worked at several occasions. However, when running the code again this week, I get an error message ‘openai.APIConnectionError: Connection error’. I reinstalled that modules and created new keys but no result.
It seems unlikely that it is a network problem since I made no change. Any ideas?
We kindly request the following information:
- Error Screenshot: Could you please provide a complete screenshot of the error message you are encountering?
- Installation Errors: During the installation of all the code, did you encounter any error messages? If so, please share the complete error details or a screenshot.
- Raspberry Pi Model: What model of Raspberry Pi are you currently using?
- System Version: Which version of the Raspberry Pi operating system are you using?
Providing these details will help us replicate the issue and work towards a solution more efficiently.
Good morning,
No installation errors. Raspberry Pi4 and OS 64bits Bookworm as recommended.
Here is the screenshot requested. The full screen is a bit long, so I provide the main extracts:
And further down:
And at the end of the process:
I checked the file Keys.py.save and the keys are well recorded.
Thank you
Daniel
Please follow the tutorial steps below:AI Interaction Using GPT-4O — SunFounder PiDog Kit 1.0 documentation
Obtain the API Key and Assistant ID
Enter the API Key and Assistant ID
Have you followed these steps? Were you able to proceed correctly?
I have followed all those steps without any problem.
I will reinstall everything from scratch. It should solve the problem. If not, I will let you know.
Thank you.
Daniel Marion
OK. Looking forward to your follow-up verification.
If you have any questions, please describe them and provide us with more information so that we can help you analyze and solve the problem.
Such as screenshots or videos.
I have reinstalled everything from scratch. Still cannot connect to openai. I suspect something with the firewall. I will continue to explore possible causes, ex: firewall.
Thanks.
If you encounter any issues or errors, please provide us with complete screenshots.
I am still looking at the network as a cause. In the meantime, and to help with my analysis, here is the full output when running the gpt example.
Thank you
Daniel Marion
daniel@raspberrypi:~ $ cd ~/pidog/gpt_examples
daniel@raspberrypi:~/pidog/gpt_examples $ sudo ~/my_venv/bin/python3 gpt_dog.py --keyboard
Traceback (most recent call last):
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_transports/default.py”, line 101, in map_httpcore_exceptions
yield
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_transports/default.py”, line 250, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py”, line 256, in handle_request
raise exc from None
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py”, line 236, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_sync/connection.py”, line 103, in handle_request
return self._connection.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_sync/http11.py”, line 136, in handle_request
raise exc
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_sync/http11.py”, line 86, in handle_request
self._send_request_headers(**kwargs)
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_sync/http11.py”, line 144, in _send_request_headers
with map_exceptions({h11.LocalProtocolError: LocalProtocolError}):
File “/usr/lib/python3.11/contextlib.py”, line 155, in exit
self.gen.throw(typ, value, traceback)
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpcore/_exceptions.py”, line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.LocalProtocolError: Illegal header value b’Bearer ’
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 955, in _request
response = self._client.send(
^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_client.py”, line 914, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_client.py”, line 942, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_client.py”, line 979, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_client.py”, line 1014, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_transports/default.py”, line 249, in handle_request
with map_httpcore_exceptions():
File “/usr/lib/python3.11/contextlib.py”, line 155, in exit
self.gen.throw(typ, value, traceback)
File “/home/daniel/my_venv/lib/python3.11/site-packages/httpx/_transports/default.py”, line 118, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.LocalProtocolError: Illegal header value b’Bearer ’
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/daniel/pidog/gpt_examples/gpt_dog.py”, line 36, in
openai_helper = OpenAiHelper(OPENAI_API_KEY, OPENAI_ASSISTANT_ID, ‘PiDog’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/pidog/gpt_examples/openai_helper.py”, line 60, in init
self.thread = self.client.beta.threads.create()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/resources/beta/threads/threads.py”, line 133, in create
return self._post(
^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 1242, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 919, in request
return self._request(
^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 979, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 1057, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 979, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 1057, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File “/home/daniel/my_venv/lib/python3.11/site-packages/openai/_base_client.py”, line 989, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
Based on this error message…
httpcore.LocalProtocolError: Illegal header value b’Bearer ’
I’d suggest that there may be a subtle syntax error in your keys file.
The python api token parser can be pedantic compared to playground. Please check that there are no “invisible” or extraneous characters in your keys file, such as spaces, tabs, extra carriage returns, line feeds etc. prior or post to your key strings.
Or other subtle anomalies or syntactical errors in the keys file, such as missing quotes etc
I created a new API key and a new Assistant, paying attention to unwanted characters. It still gives me the same error message. I will continue to investigate the network aspect. Thanks.
I’m not sure why you generated new API keys, ɓut ok. Good luck!
If you’ve confirmed your API Key and Assistant ID are correct:
- Test your assistant directly on OpenAI’s web platform
- If errors appear after sending messages, you may have:
- Hit usage limits
- Billing/payment issues
Check your:
✓ [Usage Dashboard]
✓ [Billing Settings]
Just in case something got corrupted while copying the keys into keys.py.
I did those steps. No error messages. All was good. Thanks.
Daniel
After having to step away for a few days, I come back with my original problem. I cannot connect to OpenAi from within the -gpt example . I still get the same error message ‘openai.APIConnectionError: Connection error’. It becomes clear that the problem is with my network a/o firewall. Is there a way to include a proxy in the application to get around the restriction? If not, I will haunt my network provider…
Sorry this restriction cannot be bypassed. To proceed, please try the following solution:
- Replace your current
keys.py
file with the one we provided:keys.py - Google Drive - Test the system again to see if it resolves the issue
It works! Thank you so much!
What I would really like to know is why the keys you provided work while the ones I created do not. Mystery!
One thing I notice is that the key you provided is about 50 characters long while the one I created on the OpenAi site is more like 100 characters long. Odd…
Since we don’t have visibility into your specific setup or the steps you’ve taken, we’d like to suggest the following troubleshooting measures:
- Please try generating the key multiple times - sometimes this can resolve temporary issues.
- We also recommend reaching out to OpenAI’s official support team, as they may have specific solutions or insights regarding this matter.