Skip to content

Instantly share code, notes, and snippets.

@zackbloom
Created July 2, 2013 19:35
Show Gist options
  • Select an option

  • Save zackbloom/5912399 to your computer and use it in GitHub Desktop.

Select an option

Save zackbloom/5912399 to your computer and use it in GitHub Desktop.
Working example of sentry cookie auth
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