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

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.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (6 by maintainers)

Most upvoted comments

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.

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.

It turned to an issue with proxy for me. Setting the proxy via the environment variables - HTTP_PROXY and HTTPS_PROXY did not work.

I had to set the proxy using the below way

import openai

openai.proxy = {
    "http": "<HTTP_PROXY>",
    "https": "<HTTPS_PROXY>"
}

This worked for me. It seems that semantic kernel isn’t referencing the env variables, and you have to manually set them.