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

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

Closed
carterwilliamson opened this issue Apr 24, 2023 · 25 comments
Labels
python Pull requests for the Python Semantic Kernel

Comments

@carterwilliamson
Copy link
Contributor

carterwilliamson commented Apr 24, 2023

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.

@carterwilliamson carterwilliamson changed the title Sample Code: OpenAI service failed to complete the prompt, APIConnectionError Sample Code: OpenAI service failed to complete the prompt, APIConnectionError issue with Python 3.10 Apr 25, 2023
@awharrison-28 awharrison-28 self-assigned this Apr 25, 2023
@poweihuang0817
Copy link
Contributor

Hello, I used Python 3.11.3 and it works. I didn't use venv but it does work. The issue you described is strange

@JJDawn
Copy link

JJDawn commented May 16, 2023

Have you solved the problem? I am having the same error.

@evchaki
Copy link

evchaki commented May 16, 2023

@alexchaomander can you take a look at this?

@alexchaomander
Copy link
Contributor

@carterwilliamson are you still running into this issue? I was able to get it to work fine using my Python 3.10 environment

@2662007798
Copy link

I have the same problem. I'm currently using python 3.11.3, which doesn't work.

@priya-27
Copy link

Facing same issue with python 3.10 inside Codespaces for semantic kernel python notebooks, any fix ?

@2662007798
Copy link

2662007798 commented May 18, 2023 via email

@hot5auce
Copy link

openai/openai-python#278

@roshan-gopalakrishnan
Copy link

If you are giving any org_id just comment it in the .env. It is optional.

@chenlucu
Copy link

chenlucu commented 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.

@priya-27
Copy link

priya-27 commented Jun 2, 2023

Yes, for me, the issue was I was using Azure open ai key and in the code in the sample python notebooks, there was a boolean flag variable for using azure open ai set to false by default.
image

so if you Get this Error, either use open ai key or turn the boolean flag to true before using azure open ai key.

@bingokunkun
Copy link

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's no use to me : (

@chenlucu
Copy link

chenlucu commented 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.

It's no use to me : (

I think this error is generally the network problem, since it was not able to make a successful http request. (http_status=None, request_id=None, which means no http status and no request id). Might be an VPN problem, or the openai server blocked your request. You'd better debug and trace the error to find the exact reason.

@balasubramanian-thiruvenkatesan
Copy link

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>"
}

@dandv
Copy link
Contributor

dandv commented Jun 7, 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.

@matthewbolanos
Copy link
Member

matthewbolanos commented Jun 12, 2023

I think I've run into the same SSL certificate something error.

And found this solution on SO:

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

After restarting the Jupyter notebook kernel, things worked.

I ran into the same issue. Thankfully this solution fixed it on my end. Is this problem specific to Macbooks or Windows as well? @JJDawn, @2662007798, @priya-27, @bingokunkun, and @dandv, are all y'all on Macbooks?

@dandv
Copy link
Contributor

dandv commented Jun 12, 2023

@matthewbolanos Yes, I'm on Ventura 13.3.1(a).

@priya-27
Copy link

priya-27 commented Jun 12, 2023 via email

@lemillermicrosoft lemillermicrosoft added the python Pull requests for the Python Semantic Kernel label Jun 13, 2023
@2662007798
Copy link

_我想_我遇到了相同的SSL证书错误。
并在 SO 上找到了这个解决方案

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

重新启动Jupyter笔记本内核后,事情开始了。

我遇到了同样的问题。值得庆幸的是,这个解决方案解决了我的问题。这个问题是否也特定于Macbook或Windows?@JJDawn@2662007798@priya-27@bingokunkun@dandv,你们都在Macbook上吗?

no is windows

@garyjkuehn
Copy link

garyjkuehn commented Jul 26, 2023

Same error where identical code works on a PC but fails on my MacBook. (side by side test). The code is using the model as deployed in our Azure subscription. (AzureTextCompletion).
Macbook = 12.6.2
python = 3.10.2

fresh venv:

Package Version


aiofiles 23.1.0
aiohttp 3.8.5
aiosignal 1.3.1
async-timeout 4.0.2
attrs 23.1.0
certifi 2023.7.22
charset-normalizer 3.2.0
click 8.1.6
frozenlist 1.4.0
idna 3.4
multidict 6.0.4
numpy 1.25.1
openai 0.27.8
pip 23.2.1
python-dotenv 1.0.0
regex 2023.6.3
requests 2.31.0
semantic-kernel 0.3.4.dev0
setuptools 58.1.0
tqdm 4.65.0
urllib3 2.0.4
yarl 1.9.2

@garyjkuehn
Copy link

Corrected on the Mac by upgrading python to version 3.11.4. All other packages previously stated remain as-is within the new virtual environment.

@quangngoc
Copy link

quangngoc commented Jul 28, 2023

I have the same issue on Debian 11, python 3.10.12:
Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the chat', APIConnectionError(message='Error communicating with OpenAI', http_status=None, request_id=None))
In the same environment, I could get response using langchain.

After checking ex.cause, I get the message:
Cannot connect to host xxx:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)')]

I finaly found that setup the environment variable SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt (for aiohttp) make it work

@nacharya1 nacharya1 added this to the R3 : Cycle 2 milestone Aug 10, 2023
@shivam-51
Copy link

Fixed on mac by running on Python 3.9 instead of 3.11. strange.

@GhimBoon
Copy link

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.

@lemillermicrosoft
Copy link
Member

We understand the issue is related to the virtual environment configuration. No changes to be made in the python SDK at present.

@lemillermicrosoft lemillermicrosoft closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
Archived in project
Status: Sprint: Done
Development

No branches or pull requests