semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

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

Open carterwilliamson opened this issue 2 years ago • 9 comments

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 avatar Apr 24 '23 23:04 carterwilliamson

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

poweihuang0817 avatar May 09 '23 06:05 poweihuang0817

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

JJDawn avatar May 16 '23 09:05 JJDawn

@alexchaomander can you take a look at this?

evchaki avatar May 16 '23 21:05 evchaki

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

alexchaomander avatar May 16 '23 21:05 alexchaomander

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

2662007798 avatar May 17 '23 07:05 2662007798

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

priya-27 avatar May 18 '23 10:05 priya-27

Partly because of network problems, I switched to the Singapore server to work

阿生 @.***

Original Email

Sender:"PRIYA BHIMJYANI"< @.*** >;

Sent Time:2023/5/18 18:07

To:"microsoft/semantic-kernel"< @.*** >;

Cc recipient:"2662007798"< @.*** >;"Comment"< @.*** >;

Subject:Re: [microsoft/semantic-kernel] Sample Code: OpenAI service failed tocomplete the prompt, APIConnectionError issue with Python 3.10 (Issue #627)

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

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

2662007798 avatar May 18 '23 10:05 2662007798

https://github.com/openai/openai-python/issues/278

hot5auce avatar May 19 '23 11:05 hot5auce

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

roshan-gopalakrishnan avatar May 24 '23 07:05 roshan-gopalakrishnan

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.

chenlucu avatar Jun 02 '23 06:06 chenlucu

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.

priya-27 avatar Jun 02 '23 06:06 priya-27

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 : (

bingokunkun avatar Jun 02 '23 07:06 bingokunkun

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.

chenlucu avatar Jun 02 '23 08:06 chenlucu

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

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.

dandv avatar Jun 07 '23 14:06 dandv

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?

madsbolaris avatar Jun 12 '23 12:06 madsbolaris

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

dandv avatar Jun 12 '23 13:06 dandv

Yes, on a mac

On Mon, 12 Jun 2023 at 5:48 PM, Matthew Bolaños @.***> wrote:

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

And found this solution on SO https://stackoverflow.com/questions/42098126/mac-osx-python-ssl-sslerror-ssl-certificate-verify-failed-certificate-verify :

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

After restarting the Jupyter notebook kernel, things worked.

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

— Reply to this email directly, view it on GitHub https://github.com/microsoft/semantic-kernel/issues/627#issuecomment-1587229159, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2EQ7LGDGK5YPGAK33GOGMLXK4CLBANCNFSM6AAAAAAXKHBWYE . You are receiving this because you were mentioned.Message ID: @.***>

priya-27 avatar Jun 12 '23 13:06 priya-27

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

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

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

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

no is windows

2662007798 avatar Jun 14 '23 07:06 2662007798

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 avatar Jul 26 '23 11:07 garyjkuehn

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.

garyjkuehn avatar Jul 28 '23 13:07 garyjkuehn

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

quangngoc avatar Jul 28 '23 16:07 quangngoc

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

shivam-51 avatar Aug 29 '23 05:08 shivam-51

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.

GhimBoon avatar Aug 31 '23 01:08 GhimBoon

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

lemillermicrosoft avatar Sep 08 '23 19:09 lemillermicrosoft