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

HTTP Error 403: Forbidden #31

Open codemurt opened 3 months ago

codemurt commented 3 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 3 months ago

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

sakurakoujirabbit commented 3 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 3 months ago

same case here

jensen1207 commented 3 months ago

same error that happened since last Friday

AshwinPathi commented 3 months ago

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

AshwinPathi commented 3 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.