# Cannot connect to Openapi

**URL:** https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904
**Category:** Robotic kit for Raspberry Pi
**Created:** [March 21, 2025, 8:26pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904 "2025-03-21T20:26:17Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 21, 2025, 8:26pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/1 "2025-03-21T20:26:17Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [March 24, 2025, 5:13am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/2 "2025-03-24T05:13:12Z")

</div>

We kindly request the following information:

1. **Error Screenshot** : Could you please provide a complete screenshot of the error message you are encountering?
2. **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.
3. **Raspberry Pi Model** : What model of Raspberry Pi are you currently using?
4. **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.

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 24, 2025, 4:40pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/3 "2025-03-24T16:40:50Z")

</div>

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:

 ![](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/7/734d9d06dfe48bc2e1abaf54c496bb68fa1ea62c.png)

And further down:

 ![](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/c/c635dfc58ba855133b8c648187f3a74a136c8d11.png)

And at the end of the process:

 ![](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/0/067d9c91c83d99190d7e2b5b345dcd068d06b019.png)

I checked the file Keys.py.save and the keys are well recorded.

Thank you

Daniel

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [March 25, 2025, 6:09am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/4 "2025-03-25T06:09:27Z")

</div>

Please follow the tutorial steps below:[AI Interaction Using GPT-4O — SunFounder PiDog Kit 1.0 documentation](https://docs.sunfounder.com/projects/pidog/en/latest/openai.html#obtain-api-key-and-assistant-id)  
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?

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 25, 2025, 7:10pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/5 "2025-03-25T19:10:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [March 26, 2025, 3:49am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/6 "2025-03-26T03:49:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 27, 2025, 8:58pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/7 "2025-03-27T20:58:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [March 28, 2025, 10:04am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/8 "2025-03-28T10:04:21Z")

</div>

If you encounter any issues or errors, please provide us with complete screenshots.

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 29, 2025, 7:38pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/9 "2025-03-29T19:38:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Spf650](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Spf650](https://forum.sunfounder.com/u/Spf650)
#### Post date: [March 30, 2025, 6:36am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/11 "2025-03-30T06:36:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 30, 2025, 8:17pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/12 "2025-03-30T20:17:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Spf650](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Spf650](https://forum.sunfounder.com/u/Spf650)
#### Post date: [March 31, 2025, 5:12am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/13 "2025-03-31T05:12:16Z")

</div>

I’m not sure why you generated new API keys, ɓut ok. Good luck!

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [March 31, 2025, 8:55am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/14 "2025-03-31T08:55:19Z")

</div>

If you’ve confirmed your **API Key** and **Assistant ID** are correct:

1. Test your assistant directly on OpenAI’s web platform
2. If errors appear after sending messages, you may have:

- Hit usage limits
- Billing/payment issues

Check your:  
✓ [Usage Dashboard]  
✓ [Billing Settings]

> **[AI Interaction Using GPT-4O — SunFounder PiDog Kit 1.0 documentation](https://docs.sunfounder.com/projects/pidog/en/latest/openai.html)**

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 31, 2025, 1:31pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/15 "2025-03-31T13:31:08Z")

</div>

Just in case something got corrupted while copying the keys into keys.py.

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [March 31, 2025, 1:32pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/16 "2025-03-31T13:32:23Z")

</div>

I did those steps. No error messages. All was good. Thanks.

Daniel

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [April 15, 2025, 7:47pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/17 "2025-04-15T19:47:54Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [April 16, 2025, 3:16am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/18 "2025-04-16T03:16:00Z")

</div>

Sorry this restriction cannot be bypassed. To proceed, please try the following solution:

1. Replace your current `keys.py` file with the one we provided:[keys.py - Google Drive](https://drive.google.com/file/d/1pGT5rVnxu4avvMMC6OHEvJtWdhV7Q78c/view?usp=drive_link)
2. Test the system again to see if it resolves the issue

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [April 16, 2025, 2:45pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/19 "2025-04-16T14:45:05Z")

</div>

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! 🙂

---

<div class="post-metadata">

### Author: ![Danmarion](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@Danmarion](https://forum.sunfounder.com/u/Danmarion)
#### Post date: [April 16, 2025, 8:14pm UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/20 "2025-04-16T20:14:01Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)
#### Post date: [April 17, 2025, 3:37am UTC](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904/21 "2025-04-17T03:37:56Z")

</div>

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:

1. Please try generating the key multiple times - sometimes this can resolve temporary issues.
2. We also recommend reaching out to OpenAI’s official support team, as they may have specific solutions or insights regarding this matter.

[Next page](https://forum.sunfounder.com/t/cannot-connect-to-openapi/2904.md?page=2)
