CharacterAI icon indicating copy to clipboard operation
CharacterAI copied to clipboard

TLSClientException

Open Myriad4Link opened this issue 1 year ago • 3 comments

Hello,

I am currently trying to run the example code with my own token and character id, however there seems to be a little problem:

from characterai import PyCAI

client = PyCAI('My Token')

char = input('Enter CHAR: ')

chat = client.chat.get_chat(char)

participants = chat['participants']

if not participants[0]['is_human']:
    tgt = participants[0]['user']['username']
else:
    tgt = participants[1]['user']['username']

while True:
    message = input('You: ')

    data = client.chat.send_message(
        chat['external_id'], tgt, message
    )

    name = data['src_char']['participant']['name']
    text = data['replies'][0]['text']

    print(f"{name}: {text}")

and Python says:

Traceback (most recent call last):
  File "C:\Users\Admin\test.py", line 7, in <module>
    chat = client.chat.get_chat(char)
  File "C:\Users\Admin\AppData\Roaming\Python\Python310\site-packages\characterai\characterai.py", line 531, in get_chat
    return PyCAI.request(
  File "C:\Users\Admin\AppData\Roaming\Python\Python310\site-packages\characterai\characterai.py", line 57, in request
    response = session.post(
  File "C:\Users\Admin\AppData\Roaming\Python\Python310\site-packages\tls_client\sessions.py", line 448, in post
    return self.execute_request(method="POST", url=url, data=data, json=json, **kwargs)
  File "C:\Users\Admin\AppData\Roaming\Python\Python310\site-packages\tls_client\sessions.py", line 405, in execute_request
    raise TLSClientExeption(response_object["body"])
tls_client.exceptions.TLSClientExeption: failed to do request: Post "https://beta.character.ai/chat/history/continue/": dial tcp 104.244.46.71:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

So is it my problem or the problem of the API - and how am I able to fix it? Appreciated if answered🥰

Myriad4Link avatar Nov 23 '23 11:11 Myriad4Link

Hi there! It seems like there's a connectivity issue when trying to establish a connection with the Character AI server. Here are a few things to check:

  1. Network Connection: Ensure your internet connection is stable.
  2. Firewall/Antivirus: Check for any software that might be blocking the connection.
  3. Server Status: Verify if the Character AI server is operational. 😅
  4. API Token: Confirm that the token you're using is correct and valid.

Hope this helps!

Karvp avatar Nov 27 '23 15:11 Karvp

I also encountered this problem.

longanhe avatar Mar 18 '24 02:03 longanhe

check on new version

kramcat avatar Apr 12 '24 10:04 kramcat