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

Cannot chat to characters because of JSON error? #79

Open
jynn12 opened this issue Jan 6, 2024 · 14 comments
Open

Cannot chat to characters because of JSON error? #79

jynn12 opened this issue Jan 6, 2024 · 14 comments

Comments

@jynn12
Copy link

jynn12 commented Jan 6, 2024

When I enter the character URL, I get this error

Traceback (most recent call last):
  File "/home/pandesal/chatbot/char.py", line 7, in <module>
    chat = client.chat.get_chat(char)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/characterai/characterai.py", line 531, in get_chat
    return PyCAI.request(
           ^^^^^^^^^^^^^^                                    File "/usr/lib/python3.11/site-packages/characterai/characterai.py", line 69, in request
    data = response.json()
           ^^^^^^^^^^^^^^^                                   File "/usr/lib/python3.11/site-packages/tls_client/response.py", line 39, in json
    return json.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                   File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/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)
@unhingedsoul
Copy link

unhingedsoul commented Jan 6, 2024

This error only occurs with chat2. All you have to do is go to the beta.character.ai website and open the chat with a character you want to chat with. Then you go to the link and change chat2 to chat like this:

https://beta.character.ai/chat2?char=xxx
https://beta.character.ai/chat?char=xxx

That's it. You don't have to change anything in the code.

@jynn12
Copy link
Author

jynn12 commented Jan 6, 2024

@unhingedsoul Thanks, it works now:)

@jynn12 jynn12 closed this as completed Jan 6, 2024
@Karvp
Copy link

Karvp commented Jan 18, 2024

It looks like there are some misunderstood things here, so I think I should note something. The error occurred because the server's response to the API request wasn't JSON; probably it is returning:
there is no history between user and character
in this case.

@jynn12 jynn12 reopened this Jan 28, 2024
@jynn12
Copy link
Author

jynn12 commented Jan 28, 2024

@Karvp Nope, It has a chat history...like a really REALLY long chat history...

Its been around 2 weeks since I've been chatting with this bot using this code

@jynn12
Copy link
Author

jynn12 commented Jan 28, 2024

Also, it seems that CharacterAI is using CloudFlare now? Could that be interfering with the code?

@Karvp
Copy link

Karvp commented Feb 4, 2024

Also, it seems that CharacterAI is using CloudFlare now? Could that be interfering with the code?

@jynn12 As long as you don't spam requests, imo :v

@jynn12
Copy link
Author

jynn12 commented Feb 4, 2024

@Karvp Nah, the same code works on other characters, but not on the one I am using. Its chat and not chat2 btw

@Karvp
Copy link

Karvp commented Feb 4, 2024

@Karvp Nah, the same code works on other characters, but not on the one I am using. Its chat and not chat2 btw

Seems tricky. Try inspecting the code 😄

Btw, srr for the unclear reply

@jynn12
Copy link
Author

jynn12 commented Feb 4, 2024

@Karvp Well, when I wrote this code, only me and God knows how it works. Now only God knows...

I'll try stripping the other functions from the code and will update here...

@RodnoiD1m0n
Copy link

@Karvp Nah, the same code works on other characters, but not on the one I am using. Its chat and not chat2 btw

im also using chat instead of chat2, but in my case, its works on one history of a character but not on other. oh, also it gives me this on send_message instead of get_chat. i tried debugging it, and it seems that characterai website returns 500 status code(internal server error) and api on line 67 tries parsing it to json which raises the error

@RodnoiD1m0n
Copy link

RodnoiD1m0n commented Feb 20, 2024

oh nvm, i did not notice that second history was using chat2, but for anyone wondering this fix from above should do:

This error only occurs with chat2. All you have to do is go to the beta.character.ai website and open the chat with a character you want to chat with. Then you go to the link and change chat2 to chat like this:

https://beta.character.ai/chat2?char=xxx https://beta.character.ai/chat?char=xxx

That's it. You don't have to change anything in the code.

(i get other error tho, but i think thats a separate issue)

edit: the other error was from pprint

@AaronJohnson02
Copy link

This error only occurs with chat2. All you have to do is go to the beta.character.ai website and open the chat with a character you want to chat with. Then you go to the link and change chat2 to chat like this:

https://beta.character.ai/chat2?char=xxx https://beta.character.ai/chat?char=xxx

That's it. You don't have to change anything in the code.

Hey, So I've tried to use the input the following link: https://beta.character.ai/chat?char=4WOVrCApi4JYwfYwU2e5eDeFalLOkGBw6IfUZPX1XVQ&source=recent-chats

But i received the following error

File /opt/conda/lib/python3.10/site-packages/characterai/characterai.py:74, in PyCAI.request(url, session, token, method, data, split, neo)
     72     raise errors.ServerError(data['comment'])
     73 elif str(data).startswith("{'detail': 'Auth"):
---> 74     raise errors.AuthError('Invalid token')
     75 elif str(data).startswith("{'status': 'Error"):
     76     raise errors.ServerError(data['status'])

AuthError: Invalid token```

@Karvp
Copy link

Karvp commented Mar 1, 2024

@AaronJohnson02 In your case, just check ur token

@kramcat
Copy link
Owner

kramcat commented Apr 12, 2024

check with the new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants