Created
July 2, 2013 19:35
-
-
Save zackbloom/5912399 to your computer and use it in GitHub Desktop.
Working example of sentry cookie auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import requests | |
| def get_csrf(): | |
| login = requests.get('https://app.getsentry.com/login/') | |
| page = BeautifulSoup(login.text) | |
| return [page.find(attrs={'name': 'csrfmiddlewaretoken'})['value'], login.cookies['sessionid']] | |
| def get_session(csrf, session): | |
| data = { | |
| 'csrfmiddlewaretoken': csrf, | |
| 'next': '/', | |
| 'username': 'hubspot-dev-exceptions', | |
| 'password': 'XXXXXXX' | |
| } | |
| resp = requests.post('https://app.getsentry.com/login/', data=data, allow_redirects=False, cookies={'csrftoken': csrf, 'sessionid': session}, headers={'Origin': 'https://app.getsentry.com', 'Referer': 'https://app.getsentry.com/login/', 'Content-Type': 'application/x-www-form-urlencoded'}) | |
| return resp.cookies['sessionid'] | |
| def make_request(csrf, session): | |
| resp = requests.get('https://app.getsentry.com/api/app-systems/katamari-api/chart/?days=7&gid=5174374', cookies={'sessionid': session, 'csrftoken': csrf}) | |
| return resp.text | |
| [csrf, session] = get_csrf() | |
| session = get_session(csrf, session) | |
| make_request(csrf, session) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment