question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sample Code: OpenAI service failed to complete the prompt, APIConnectionError issue with Python 3.10

See original GitHub issue

Describe the bug Unable to run the sample code here: https://github.com/microsoft/semantic-kernel/blob/main/python/README.md

To Reproduce Steps to reproduce the behavior:

  1. Create new virtual environment python -m venv venv
  2. python -m pip install --upgrade semantic-kernel
  3. Create a .env file following these instructions: https://github.com/microsoft/semantic-kernel/blob/main/python/README.md#openai--azure-openai-api-keys
  4. Copy this code - https://github.com/microsoft/semantic-kernel/blob/main/python/README.md#running-a-prompt into a file named main.py
  5. Error: Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the prompt', APIConnectionError(message='Error communicating with OpenAI', http_status=None, request_id=None))

Expected behavior Expected to see output like Robots must not harm humans.

Desktop (please complete the following information):

  • OS: Mac 12.6.1
  • IDE: VS Code
  • openai == 0.27.4
  • semantic-kernel == 0.2.4.dev0
  • numpy == 1.24.3
  • python == 3.10.8

Additional context Full error: Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the prompt', APIConnectionError(message='Error communicating with OpenAI', http_status=None, request_id=None))

No VPN enabled. New virtual environment. Tried with my personal account as well as my company account. Both had same result. Tried on a VPN, no luck.

Edit:

I was able to run the sample in an AWS ec2 instance with python 3.9. I then tested on my machine with a python:3.9 docker container which also worked. This appears to be an issue with python 3.10.

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
dandvcommented, Jun 12, 2023

I think I’ve run into the same SSL certificate something error on macOS.

And found this solution on SO:

bash /Applications/Python*/Install\ Certificates.command

After restarting the Jupyter notebook kernel, things worked.

1reaction
chenlucucommented, Jun 2, 2023

I got the same problem. I traced the error and found that it was not able to verify the local issuer certificate. Cannot connect to host xxxxxx.openai.azure.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')] So I added a config setting in the source code(openai/api_requestor.py line 586): image This will ignore the verification of SSL certificate, and this fixed my problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error codes - OpenAI API
Python library error types ; APIConnectionError, Cause: Issue connecting to our services. Solution: Check your network settings, proxy configuration, SSL ...
Read more >
"InvalidRequestError: Resource not found". Please help to fix.
Code has been taken from sample given and key has been tried as key1 and key2 both separately. Same error is found. python...
Read more >
API aborts my connection without a reason - anything I can ...
I am making python calls to the API via the openai library. ... APIConnectionError: Error communicating with OpenAI: ('Connection aborted.
Read more >
openai.error.APIConnectionError: Error communicating ...
My situation: windows; intranet with proxy. try to: setting\env add 「OPENAI_PROXY:http://user:password@proxy server ip ...
Read more >
API timeout after inactivity (python)
When my python program doesn't use the API for couple of hours or days, ... by APIConnectionError Exception after minutes of inactivity.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found