st1vms/unofficial-claude-api

Error code 200, response -> {}

ermaxinc opened this issue ยท 7 comments

Sometimes I get an error

Error code 200, response -> {} 

My code:

if file is not None and os.path.exists(file):
    res: SendMessageResponse = client.send_message(
        chat_id=chat_id, prompt=text, attachment_paths=[file]
    )
else:
    res: SendMessageResponse = client.send_message(
        chat_id=chat_id, prompt=text
    )

if res.answer:
    result_answer = res.answer
else:
    self.__msg.error(f'Error code {res.status_code}, response -> {res.error_response} // MSG:{msg_num}', than_exit=False)
    self.__msg.error(f'{res}', than_exit=True)

res is:

SendMessageResponse(answer='', status_code=200, error_response={}) 

Any idea how fix this?

PS. But if i go to the Web, there's an answer in chat.

st1vms commented

Hi @ermaxinc, I have to know if this bug occurs multiple times in a row, or it's just some random error you encountered... also can I have a clue about the file content you're sending as attachment?

Since the status_code returned is 200, I'm guessing there is probably something wrong either in the ClaudeAPIClient.__decode_response() method (see this line ) or in the way the response is parsed as text ( here )

I may need to gather more info about this error before pushing a fix.

st1vms commented

More specifically I have to look for unproper decoding of responses ( if the compression took place ).

Also there should probably be a better way of parsing the response into the answer string object.

  1. The error occurs often (I use many accounts + multi-thread)
  2. I send messages to the chat, in this chat there are messages with files and there are also messages without files.
  3. The errors that I tried to track down were all without files, i.e. messages that were sent to the chat were without files, and I received an error for them

This is last error, msg without file
Error

st1vms commented

@ermaxinc Are you able to inspect the response body of the send_message post request?

Can you please do that by running this library from source?

  1. Download this repo
  2. Install it using pip install -e . inside the repo folder.
  3. Inspect the response.content object in this line

It would be a lot helpful to understand the actual response you're getting...

Thanks in advance

@st1vms I'm sorry it took me so long to respond.
I found the problem. It's Claude overloading.

response.content

b'data: {"error":{"type":"overloaded_error","message":"Overloaded"}}\n\n'

Need to make the following logic of behavior.
If we get an overload, we wait 5 seconds and execute send_message again

In the web version, it looks like this:
2024-01-26

st1vms commented

@ermaxinc Thanks a lot for your feedback. Based off the response.content you provided, it seems that a new exception wrapping this error is what we need...

But also the error_response basically doesn't give any actual clue about any potential errors, the reason is because of a stinky json parsing strategy...so I think it's best off to let there be a property such as raw_answer, or smth like that, holding the response.content itself.

I'll be making a PR to test these things out whenever possible, meanwhile if you'd like to push your help, feel free to do the same.

Thanks again :)

st1vms commented

@ermaxinc Let's move the discussion here... #13

Waiting for your confirmation in order to push the new changes into the 0.2.7 release : )