AshwinPathi / claude-api-py

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

HTTP Error 403: Forbidden #31

Open codemurt opened 8 months ago

codemurt commented 8 months ago

I'm trying to run this code:

from claude import claude_client
from claude import claude_wrapper
SESSION_KEY = <MY_SESSION_KEY>
client = claude_client.ClaudeClient(SESSION_KEY)
organizations = client.get_organizations()
organizations

but I get this:

WARNING:root:Failed response object: Response(ok=False, data=b'', status_code=None, error='HTTP Error 403: Forbidden')
None

I don't really understand what the problem is.

AshwinPathi commented 8 months ago

Could you dump the logs, try a different session key, or try a different account?

sakurakoujirabbit commented 8 months ago

I have the same problem. [17-Mar-24 18:10: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') None

gerkim62 commented 8 months ago

same case here

jensen1207 commented 8 months ago

same error that happened since last Friday

AshwinPathi commented 8 months ago

same, probably some additional headers or security was added recently.

AshwinPathi commented 8 months ago

@jensen1207 @gerkim62 @sakurakoujirabbit @codemurt

The problem is anthropic uses cloudflare cookies to prevent bots. These cookies refresh periodically, so this probably isn't a permanent solution. The "real" best way to solve this would be to completely mock the browser or find some way to bypass cloudflare cookies. The former is too heavyweight and the latter might be difficult.

Since this is also kind of against their TOS, I don't think I can comment more.

Kneegrowtreegrow commented 2 weeks ago

User Cookie_browser3

import browser_cookie3

cj = browser_cookie3.chrome(domain_name='claude.ai') cookies = {cookie.name: cookie.value for cookie in cj}

print(cj)

print(cookies)

You can get all the present cookies from the chrome browser even the cloudflare cookies.