Skip to content

Instantly share code, notes, and snippets.

@tjvr
Last active October 31, 2015 15:27
Show Gist options
  • Save tjvr/0085c5315f89c83e7fcb to your computer and use it in GitHub Desktop.
Save tjvr/0085c5315f89c83e7fcb to your computer and use it in GitHub Desktop.
chocpi.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"session = requests.Session()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"r = session.get('https://scratch.mit.edu/csrf_token')\n",
"assert r.status_code == 200"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'UPC8l3Lg7rE09AuLro9elJI8s901X3j6'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"csrf_token = session.cookies['scratchcsrftoken']\n",
"csrf_token"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"r = session.post('https://scratch.mit.edu/accounts/login/',\n",
" headers = {\n",
" 'Referer': 'https://scratch.mit.edu/',\n",
" 'X-CSRFToken': csrf_token,\n",
" 'X-Requested-With': 'XMLHttpRequest',\n",
" },\n",
" json = dict(\n",
" username = 'blob8108',\n",
" password = PASSWORD,\n",
" csrftoken = csrf_token,\n",
" ),\n",
")\n",
"assert r.status_code == 200"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[{'id': 24232,\n",
" 'messages': [],\n",
" 'msg': '',\n",
" 'num_tries': 1,\n",
" 'success': 1,\n",
" 'username': 'blob8108'}]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r.json()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"r = session.get('https://scratch.mit.edu/session/')\n",
"assert r.status_code == 200"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'flags': {'confirm_email_banner': True,\n",
" 'has_outstanding_email_confirmation': False,\n",
" 'show_welcome': True,\n",
" 'unsupported_browser_banner': True},\n",
" 'permissions': {'admin': False, 'educator': False, 'social': True},\n",
" 'user': {'dateJoined': '2007-06-19T11:45:41',\n",
" 'id': 24232,\n",
" 'thumbnailUrl': '//cdn2.scratch.mit.edu/get_image/user/24232_32x32.png?v=1377613832.0',\n",
" 'username': 'blob8108'}}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r.json()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment