AshwinPathi / claude-api-py

Unofficial Python API for Anthropic's Claude LLM
https://pypi.org/project/claude-api-py/
MIT License
108 stars 11 forks source link

Bug: We are unable to serve your request #29

Closed linkedlist771 closed 3 months ago

linkedlist771 commented 3 months ago

In code:

    encoded_request_body = json.dumps(request_body).encode()
    try:
        response = urlopen(request, data=encoded_request_body)
        client = sseclient.SSEClient(response)
        for event in client.events():
            yield event.data
    except (HTTPError, URLError) as e:
        logger.logger.info("SEE POST failed with error: %s", str(e))
        print(e)

I got the following error:

{"error": {"type": "permission_error", "message": "We are unable to serve your request"}}

No idea why, just copy paste the access token.

AshwinPathi commented 3 months ago

Can you paste the full error log? You might need to use a VPN if you are connecting from outside of the US.

linkedlist771 commented 3 months ago

Here is the detailed output, I have masked the private part, please check it out:


URL: https://claude.ai/api/organizations/a86bb297-4290-4ff6-a3d8-50bbd063e687/chat_conversations/4aff8cbd-32c3-49c9-8d33-06e389163748/completion
Traceback (most recent call last):
  File "/root/GitHubProject/claude_api/example.py", line 116, in <module>
    main()
  File "/root/GitHubProject/claude_api/example.py", line 44, in main
    new_convo_response = claude_obj.start_new_conversation("New Conversation", "Hi Claude!", model=model)
  File "/root/GitHubProject/claude_api/claude/claude_wrapper.py", line 103, in start_new_conversation
    send_init_message_result = self._client.send_message(
  File "/root/GitHubProject/claude_api/claude/claude_client.py", line 72, in send_message
    for elem in self._send_message(
  File "/root/GitHubProject/claude_api/claude/claude_client.py", line 341, in _send_message
    for streamed_data_chunk in custom_requests.sse(
  File "/root/GitHubProject/claude_api/claude/custom_requests.py", line 213, in sse
    client = sseclient.SSEClient(response)
  File "/root/miniconda3/lib/python3.9/site-packages/sseclient.py", line 48, in __init__
    self._connect()
  File "/root/miniconda3/lib/python3.9/site-packages/sseclient.py", line 56, in _connect
    self.resp = requester.get(self.url, stream=True, **self.requests_kwargs)
  File "/root/miniconda3/lib/python3.9/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/root/miniconda3/lib/python3.9/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/root/miniconda3/lib/python3.9/site-packages/requests/sessions.py", line 575, in request
    prep = self.prepare_request(req)
  File "/root/miniconda3/lib/python3.9/site-packages/requests/sessions.py", line 486, in prepare_request
    p.prepare(
  File "/root/miniconda3/lib/python3.9/site-packages/requests/models.py", line 368, in prepare
    self.prepare_url(url, params)
  File "/root/miniconda3/lib/python3.9/site-packages/requests/models.py", line 439, in prepare_url
    raise MissingSchema(
requests.exceptions.MissingSchema: Invalid URL '<http.client.HTTPResponse object at 0x7f6b0240e820>': No scheme supplied. Perhaps you meant https://<http.client.HTTPResponse object at 0x7f6b0240e820>?
(base) [root@almalinux-8 claude_api]# curl ipinfo.io
{
  "ip": "198xxxx34",
  "hostname": "198-xxx-34-host.colocrossing.com",
  "city": "Buffalo",
  "region": "New York",
  "country": "US",
  "loc": "42.8865,-78.8784",
  "org": "AS36352 HostPapa",
  "postal": "14202",
  "timezone": "America/New_York",
  "readme": "https://ipinfo.io/missingauth"
AshwinPathi commented 3 months ago

This looks like a different error? Could you try using your native request headers instead and try a new cookie?

linkedlist771 commented 3 months ago

I've encountered a new issue when attempting to execute a script in my environment. The error log is as follows:

(base) [root@almalinux-8 claude_api]# python example.py
[16-Mar-24 11:40:48:root:WARNING][claude_client.py:304 - get_organizations() ] Failed response object: Response(ok=False, data=b'', status_code=None, error='HTTP Error 403: Forbidden')
Traceback (most recent call last):
  File "/root/GitHubProject/claude_api/example.py", line 116, in <module>
    main()
  File "/root/GitHubProject/claude_api/example.py", line 31, in main
    claude_obj = claude_wrapper.ClaudeWrapper(client, organizations[0]['uuid']) # type: ignore
TypeError: 'NoneType' object is not subscriptable

It appears I'm unable to retrieve my organization's information now. Can you reproduct it?

AshwinPathi commented 3 months ago

Usually this happens when you get banned