openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
22.96k stars 3.22k forks source link

Suspect issues on python 3.11.2 with error: AttributeError: module 'subprocess' has no attribute 'PIPE' due to white space in file path #365

Closed mithunsridharan closed 1 year ago

mithunsridharan commented 1 year ago

Describe the bug

I'm facing issues with openai on Python 3.11.2. When I run the demo code, I'm getting the following issues. I suspect there's an issue due to a space in the Python file path. Please let me know of any workaround or fixes:

Please note that the Python script is in a folder: Z. Temp This folder has a space.

/Users/mithun % /usr/local/bin/python3 "/Users/mithun/Documents/Z. Temp/Python/GPT_Test2.py" Traceback (most recent call last): File "/Users/mithun/Documents/Z. Temp/Python/GPT_Test2.py", line 1, in import openai File "/usr/local/lib/python3.11/site-packages/openai/init.py", line 9, in from openai.api_resources import ( File "/usr/local/lib/python3.11/site-packages/openai/api_resources/init.py", line 1, in from openai.api_resources.audio import Audio # noqa: F401 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openai/api_resources/audio.py", line 4, in from openai import api_requestor, util File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 1, in import asyncio File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/init.py", line 8, in from .base_events import * File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 40, in from . import events File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 203, in class AbstractEventLoop: File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 511, in AbstractEventLoop stdin=subprocess.PIPE, ^^^^^^^^^^^^^^^ AttributeError: module 'subprocess' has no attribute 'PIPE'

However, when I run the sample code from MacOS Desktop, I'm no longer getting the subprocess error, but rather the expected API key error. Note that the file path does not have any spaces.

/Users/mithun % /usr/local/bin/python3 /Users/mithun/Desktop/GPT_Test2.py Traceback (most recent call last): File "/Users/mithun/Desktop/GPT_Test2.py", line 5, in models = openai.Model.list() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openai/api_resources/abstract/listable_apiresource.py", line 60, in list response, , api_key = requestor.request( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 226, in request resp, got_stream = self._interpret_response(result, stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 619, in _interpret_response self._interpret_response_line( File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 682, in _interpret_response_line raise self.handle_error_response( openai.error.AuthenticationError: Incorrect API key provided: sk-dvmDm***po9e. You can find your API key at https://platform.openai.com/account/api-keys.

To Reproduce

Execute the sample code on MacOS Desktop and another folder with a space in the file path

Code snippets

import openai
openai.api_key = "sk-xxxx"

# list models
models = openai.Model.list()

# print the first model's id
print(models.data[0].id)

# create a completion
completion = openai.Completion.create(model="ada", prompt="Hello world")

# print the completion
print(completion.choices[0].text)

OS

macOS

Python version

Python v3.11.2

Library version

openai-python v0.27.2

hallacy commented 1 year ago

Hi @mithunsridharan! I can't create this with the reproduction steps above. I strongly suspect a configuration issue on your side (either a conflicting file name / module with subprocess, or something else in your dev setup). Please let me know if you have other steps that might help me reproduce the error.