Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing a Blogpost #1

Closed
MLWhiz opened this issue Jul 16, 2023 · 9 comments
Closed

Writing a Blogpost #1

MLWhiz opened this issue Jul 16, 2023 · 9 comments

Comments

@MLWhiz
Copy link

MLWhiz commented Jul 16, 2023

Hey Ashwin

Great effort. Would it be alright if I write an Medium post for this repo?

Thanks

@AshwinPathi
Copy link
Owner

@MLWhiz It's still unstable so there are no guarantees it'll work, but if you're able to actually use it I don't mind if you post about it.

@MLWhiz
Copy link
Author

MLWhiz commented Jul 16, 2023 via email

@AshwinPathi
Copy link
Owner

AshwinPathi commented Jul 16, 2023

@MLWhiz The API supports providing a spoofed header that you can use to bypass 403s.

You can find these headers by going to the claude website, initiating a chat, opening up inspect element, going to the networks tab, and copying the headers that your browser uses to send requests. Convert that header to a python dictionary and you can pass it into the API like so:

session_key = ...
spoofed_headers = {'user-agent': ..., 'accept': ..., ...}
api = ClaudeAPI(session_key, spoofed_headers=spoofed_headers)

I haven't experimented with what headers actually matter, but I'd wager that the necessary one is the user-agent header. Let me know if that works.

@MLWhiz
Copy link
Author

MLWhiz commented Jul 16, 2023 via email

@AshwinPathi
Copy link
Owner

AshwinPathi commented Jul 16, 2023

@MLWhiz did you just use User-Agent or did you spoof the full set of headers that the browser sends? Also, which requests does it fail on?

For example, it should look something like this:

# Some fields left out since these are browswer specific. Find them using inspect element.
CUSTOM_HEADERS = {
    'authority': 'claude.ai',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'accept-language': 'en-US,en;q=0.9',
    'cache-control': 'max-age=0',
    'dnt': '1',
    'sec-ch-ua': '{Broswer metadata}',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'same-origin',
    'upgrade-insecure-requests': '1',
    'user-agent': '{user agent of choice}',
}

You can try this header but its probably best to generate one on your own using the method I mentioned before. I just tested it out and it works locally, let me know if this fixes the issue.

Keep in mind if you pull the headers directly from inspect element it'll also contain a header section for cookies - delete this section when you use the headers in the code since you already provide cookies through the session_key constructor argument.

@MLWhiz
Copy link
Author

MLWhiz commented Jul 16, 2023 via email

@AshwinPathi
Copy link
Owner

@MLWhiz were you able to get it to work? I'll close the issue if you did.

@MLWhiz
Copy link
Author

MLWhiz commented Jul 17, 2023 via email

@AshwinPathi
Copy link
Owner

@MLWhiz Cool. Looking forward to reading the article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants