wwwzhouhui / Claude2-PyAPI

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

企业微信应用发送消息报错 #20

Closed pasalai closed 1 year ago

pasalai commented 1 year ago

ImApp.py运行后发送消息报错如下

[2023-09-04 04:16:36,824] ERROR in app: Exception on /wechat [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 203, in _new_conn
    sock = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 776, in urlopen
    self._prepare_proxy(conn)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1041, in _prepare_proxy
    conn.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 611, in connect
    self.sock = sock = self._new_conn()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 218, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f105b7f8280>: Failed to establish a new connection: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

urllib3.exceptions.ProxyError: ('Unable to connect to proxy', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f105b7f8280>: Failed to establish a new connection: [Errno 111] Connection refused'))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='qyapi.weixin.qq.com', port=443): Max retries exceeded with url: /cgi-bin/message/send?access_token=1000005 (Caused by ProxyError('Unable to connect to proxy', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f105b7f8280>: Failed to establish a new connection: [Errno 111] Connection refused')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/home/claude/channel/wechatcom/wechatenterprise_channel.py", line 25, in handler_msg
    return WechatEnterpriseChannel().handle()
  File "/home/claude/channel/wechatcom/wechatenterprise_channel.py", line 89, in handle
    self.client.message.send_text(self.AppId,msg.source,reply)
  File "/usr/local/lib/python3.10/site-packages/wechatpy/enterprise/client/api/message.py", line 62, in send_text
    return self.send(
  File "/usr/local/lib/python3.10/site-packages/wechatpy/enterprise/client/api/message.py", line 58, in send
    return self._post('message/send', data=data)
  File "/usr/local/lib/python3.10/site-packages/wechatpy/client/api/base.py", line 19, in _post
    return self._client.post(url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/wechatpy/client/base.py", line 182, in post
    return self._request(
  File "/usr/local/lib/python3.10/site-packages/wechatpy/client/base.py", line 85, in _request
    res = self._http.request(
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 513, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='qyapi.weixin.qq.com', port=443): Max retries exceeded with url: /cgi-bin/message/send?access_token=1000005 (Caused by ProxyError('Unable to connect to proxy', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f105b7f8280>: Failed to establish a new connection: [Errno 111] Connection refused')))
183.47.98.227 - - [04/Sep/2023 04:16:36] "POST /wechat?msg_signature=0c10c5427f385f5346b577e89f3c350fc2706cbd&timestamp=1693800996&nonce=1693700453 HTTP/1.1" 500 -
No ID found. Creating new ID
[ERROR][2023-09-04 04:16:36][wechatenterprise_channel.py:57] - You are using http proxy WRONG, the prefix should be 'http://' not 'https://',see: https://github.com/yifeikong/curl_cffi/issues/6
Traceback (most recent call last):
  File "/home/claude/channel/wechatcom/wechatenterprise_channel.py", line 53, in _do_send
    reply_text = super().build_reply_content(query, context)
  File "/home/claude/channel/channel.py", line 31, in build_reply_content
    return Bridge().fetch_reply_content(query, context)
  File "/home/claude/bridge/bridge.py", line 11, in fetch_reply_content
    return bot_factory.create_bot("claudeAI").reply(query, context)
  File "/home/claude/bot/claude/claude_ai_bot.py", line 19, in reply
    result= self.create_chat(query,Conversation_id)
  File "/home/claude/bot/claude/claude_ai_bot.py", line 30, in create_chat
    client = Client(self.cookie,self.isproxy)
  File "/home/claude/claude_api.py", line 18, in __init__
    self.organization_id =self.get_organization_id()
  File "/home/claude/claude_api.py", line 51, in get_organization_id
    response = self.send_request("GET",url,headers=headers)
  File "/home/claude/claude_api.py", line 325, in send_request
    return requests.request(method, url, headers=headers, data=data, files=files, params=params,impersonate="chrome110",proxies=self.proxies,timeout=500)
  File "/usr/local/lib/python3.10/site-packages/curl_cffi/requests/__init__.py", line 46, in request
    return s.request(
  File "/usr/local/lib/python3.10/site-packages/curl_cffi/requests/session.py", line 407, in request
    req, buffer, header_buffer = self._set_curl_options(
  File "/usr/local/lib/python3.10/site-packages/curl_cffi/requests/session.py", line 267, in _set_curl_options
    raise RequestsError(
curl_cffi.requests.errors.RequestsError: You are using http proxy WRONG, the prefix should be 'http://' not 'https://',see: https://github.com/yifeikong/curl_cffi/issues/6
pasalai commented 1 year ago

config.json文件中的"isproxy": "True",或者设为False都是这个报错

pasalai commented 1 year ago

已参考解决: https://github.com/wwwzhouhui/Claude2-PyAPI/issues/2