wwwzhouhui / Claude2-PyAPI

一个使用python 实现Claude2 创建会话、聊天、发送附件、获取历史会话,清理历史记录等功能的api接口,可以对接第三方系统作为二次开发使用。
MIT License
308 stars 50 forks source link

Failed to perform, ErrCode: 23, Reason: 'Failure writing output to destination'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details. #28

Open roaringmyshallowwater opened 10 months ago

roaringmyshallowwater commented 10 months ago
    def send_message(self, prompt, conversation_id, attachment=None):
        # ......
        buffer = BytesIO()
        c = Curl()
        headers_list = [f"{k}: {v}".encode() for k, v in headers.items()]

        def stream_callback(data):
            json_str = data.decode('utf-8')
            decoded_data = re.sub('\n+', '\n', json_str).strip()
            data_strings = decoded_data.split('\n')
            for data_string in data_strings:
                json_str = data_string[6:].strip()
                _data = json.loads(json_str)
                if 'completion' in _data:
                    buffer.write(str(_data['completion']).encode('utf-8'))
                    print(_data['completion'], end="")

        c.setopt(CurlOpt.URL, b'https://claude.ai/api/append_message')
        c.setopt(CurlOpt.WRITEFUNCTION, stream_callback)
        c.setopt(CurlOpt.HTTPHEADER, headers_list)
        c.setopt(CurlOpt.POSTFIELDS, payload)
        c.impersonate("chrome110")
        c.perform()
        c.close()
        body = buffer.getvalue()
        print(body.decode())
        return body

报错如下

    response = claude.send_message(user_input, conversation_id)
  File "E:\0nlp\split\Claude-API-main\claude-api\claude_api.py", line 181, in send_message
    c.perform()
  File "E:\0nlp\split\Claude-API-main\venv\lib\site-packages\curl_cffi\curl.py", line 251, in perform
    self._check_error(ret, action="perform")
  File "E:\0nlp\split\Claude-API-main\venv\lib\site-packages\curl_cffi\curl.py", line 106, in _check_error
    raise error
curl_cffi.curl.CurlError: Failed to perform, ErrCode: 23, Reason: 'Failure writing output to destination'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details.
2922832737C commented 10 months ago

我也遇到这个问题了,请问你解决了吗

Gyxqq commented 10 months ago

这是来自QQ邮箱的自动回复邮件。邮件已收到​

Mou-Mou-L commented 9 months ago

我也遇到这个问题了,请问你解决了吗

raise RequestsError(str(e), e.code, rsp) from e curl_cffi.requests.errors.RequestsError: Failed to perform, ErrCode: 7, Reason: 'Failed to connect to 127.0.0.1 port 10808 after 2031 ms: Connection refused'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details. 遇到了以上错误 不知道一样不

2922832737C commented 9 months ago

@Mou-Mou-L 你的好像是代理的问题

Mou-Mou-L commented 9 months ago

@2922832737C 大佬 我用的clash代理 可以帮我指点一下么

Mou-Mou-L commented 9 months ago

@2922832737C 大佬 我用的clash代理 可以帮我指点一下么

@2922832737C 大佬 我用的clash代理 可以帮我指点一下么

qq 1241329431

Mou-Mou-L commented 9 months ago

@2922832737C 在帮忙看个问题吧 大佬 send 和chat模式 我都按照原始导入的post请求参数执行的 现在程序报如下错误: self._headers = lib.curl_slist_append(self._headers, header) TypeError: initializer for ctype 'char *' must be a bytes or list or tuple, not str

caicaicaibeiqie commented 8 months ago

@Mou-Mou-L 我也遇到了一样的问题。在使用tracebak打印调用处。

Gyxqq commented 8 months ago

这是来自QQ邮箱的自动回复邮件。邮件已收到​

caicaicaibeiqie commented 8 months ago

@Mou-Mou-L 其中获取conversation_id使用的是send_requests方式请求,调用的_set_curl_options有转码的逻辑,遗憾的是我暂时还没找到这个模块。 而send_message直接使用curl的setopt时就会报编码错误。我尝试在curl中对headers判断并转码,结果依然报错。目前还在debug中,如果有新的进展可以一起讨论分享

caicaicaibeiqie commented 8 months ago

c.perform()写入失败错误,可能的原因如下: 1、文件/文件夹权限问题,检查待写入的目标文件是否有访问权限,如果使用的是buffer,则忽略这一步。 2、cache溢出导致的buffer无法写入,检查项目资源状态,必要时在每次使用完buffer后调用buffer.seek(0) buffer.truncate(0)来主动清理。 3、由于claude采用的是流式返回,当处理一些较为复杂,返回token较多的问题所需时间可能比较长,如果你已经将项目部署或者在config中配置了最长等待时间,这个返回过程就会因超时而被中断。建议检查下flask的conf配置以及你所部署服务器的nginx超时配置,如果以上方法都无法解决,期待进一步的探讨