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.
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.
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.
- The error occurs often (I use many accounts + multi-thread)
- I send messages to the chat, in this chat there are messages with files and there are also messages without files.
- 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
@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?
- Download this repo
- Install it using
pip install -e .
inside the repo folder. - 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
@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 :)