labteral / chatgpt-python

Unofficial Python SDK for OpenAI's ChatGPT
https://labteral.github.io/chatgpt-python/
GNU General Public License v3.0
523 stars 76 forks source link

crash during parsing the json file #1

Open JaceyMarvin99 opened 1 year ago

JaceyMarvin99 commented 1 year ago

using python 3.10

my code was

from chatgpt import Conversation

conversation = Conversation()
print(
    conversation.chat("Hello!")
)

I got

Traceback (most recent call last):
  File "...", line 6, in <module>
    conversation.chat("Hello!")
  File "C:\Program Files\Python\Python310\lib\site-packages\chatgpt\chatgpt.py", line 83, in chat
    error_message = json.loads(payload)['detail']
  File "C:\Program Files\Python\Python310\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Python\Python310\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I stored the result of interceptor.js in config.json correcly before I run the code. It was

{
"access_token":"...",
"conversation_id":"...",
"parent_message_id":"..."
}
kenngkz commented 1 year ago

I encountered the same error. I believe it is caused by an authentication error thrown by the OpenAI API.

I added the line print(f"ERROR: payload = {payload}") before line 83 on chatgpt\chatgpt.py and the output to console when i ran it was:

ERROR: payload = <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta content='text/html; charset=utf-8' http-equiv='content-type'/><style type='text/css'>body { font-family:Arial; margin-left:40px; }img  { border:0 none; }#content { margin-left: auto; margin-right: auto }#message h2 { font-size: 20px; font-weight: normal; color: #000000; margin: 34px 0px 0px 0px }#message p  { font-size: 13px; color: #000000; margin: 7px 0px 0px 0px }#errorref { font-size: 11px; color: #737373; margin-top: 41px }</style><title>Microsoft</title></head><body><div id='content'><div id='message'><h2>The request is blocked.</h2></div><div id='errorref'><span>0/m2PYwAAAAAH9LLwx3+3QKxJna0IDJrmTE9OMjFFREdFMTYxMABlNjZiOGIwMy0wNzkzLTQ0MDktOTc3My0yZTYxMmU3MWExZTM=</span></div></div></body></html>

To me it looks like the authentication token generated by interceptor.js is somehow invalid (i dont have any expertise in js). Perhaps one of the developers can take a look into this.

brunneis commented 1 year ago

Hi @somenothing, @kenngkz!

@AlexSua has been doing an amazing job improving the library. Changes in the OpenAI's backend broke the library but it is already working again. Now it can log in directly with an email and password.

You can update the library with pip install -U chatgpt and create a config.json file with the following information:

{
    "email": "email@example.org",
    "password": "xxx"
}
JaceyMarvin99 commented 1 year ago

Now it can log in directly with an email and password.

It works! Thanks!

betimd commented 1 year ago

It seems again to having a problem w/ login. I get "Login error. Try again or insert the token yourself."

betimd commented 1 year ago

Just to add more context, I added all params (access_token, session) including email and password and it's failing again.

daangeijs commented 1 year ago

It seems again to having a problem w/ login. I get "Login error. Try again or insert the token yourself."

This is mainly caused on the backend side of ChatGPT. It is having high traffic problems, which causes some login problems. Look carefully in the stacktrace and you will see that it sometimes is a refused connection, timeout, captcha prompt etc.

Just to add more context, I added all params (access_token, session) including email and password and it's failing again.

Again this is most likely also caused by the OpenAI backend, howevver, if you use it in a python lib you can login manually and make sure to set the config.json path:

model._config_path = 'config.json'
model.login(username, password)

You can also disable the config.json generation when creating a new session by disabling these lines, so you can check make sure that it will generate new keys and not load old ones: https://github.com/labteral/chatgpt-python/blob/f2d632bbe28fe7b7725169119092df39f262d1e8/chatgpt/chatgpt.py#L357 https://github.com/labteral/chatgpt-python/blob/f2d632bbe28fe7b7725169119092df39f262d1e8/chatgpt/chatgpt.py#L404