terry3041 / pyChatGPT

An unofficial Python wrapper for OpenAI's ChatGPT API
GNU General Public License v3.0
1.35k stars 255 forks source link

Script used to work, doesn't anymore #110

Open deezed420 opened 1 year ago

deezed420 commented 1 year ago

My script doesn't work anymore but it used to flawlessly. Here is the error:

Traceback (most recent call last):
  File "c:\Users\Ender\Dev\Test\main.py", line 9, in <module>
    api = ChatGPT(sessiontoken)
          ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyChatGPT\pyChatGPT.py", line 125, in __init__
    self.__init_browser()
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyChatGPT\pyChatGPT.py", line 221, in __init_browser
    self.__ensure_cf()
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyChatGPT\pyChatGPT.py", line 266, in __ensure_cf
    raise ValueError('Invalid session token')
ValueError: Invalid session token
Exception ignored in: <function ChatGPT.__del__ at 0x000001FD9A447C40>
Traceback (most recent call last):
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyChatGPT\pyChatGPT.py", line 134, in __del__
    self.driver.quit()
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 732, in quit
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
Exception ignored in: <function Chrome.__del__ at 0x000001FD9A32B600>
Traceback (most recent call last):
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 777, in __del__
  File "C:\Users\Ender\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 732, in quit
OSError: [WinError 6] The handle is invalid

And here is my script

from pyChatGPT import ChatGPT # Import ChatGPT API

# Variables
questions = []
answers = []
sessiontoken = Thats a No No

# Start the api
api = ChatGPT(sessiontoken)

# Read questions
with open("./questions.txt", "r") as f: questions += f.readlines()

# Send query to api
for q in questions: response = api.send_message(q) ; answers.append(response["message"])

# Clean up answers list
answers = [a[:-1] for a in answers]

# Write answers to file
with open("./answers.txt", "w") as f: f.write(''.join(answers))

# Close chrome window
api.clear_conversations()
api.driver.close()

I am trying to read questions from a file, and write the answers from ChatGPT into another file.

terry3041 commented 1 year ago

session_token expired.