Skip to content

Instantly share code, notes, and snippets.

@Zsailer
Created February 8, 2018 00:32
Show Gist options
  • Save Zsailer/7b675c84b4fd19196bb2d49f1ae52141 to your computer and use it in GitHub Desktop.
Save Zsailer/7b675c84b4fd19196bb2d49f1ae52141 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from subprocess import Popen"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env = os.environ.copy()\n",
"env['JUPYTERHUB_API_TOKEN'] = 'secret'\n",
"\n",
"p = Popen(['jupyterhub'], env=env)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"s = requests.Session()\n",
"s.headers['Authorization'] = 'token secret'"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'content': [{'content': None,\n",
" 'created': '2018-02-01T23:27:53.692283Z',\n",
" 'format': None,\n",
" 'last_modified': '2018-02-01T23:27:53.692283Z',\n",
" 'mimetype': None,\n",
" 'name': 'test',\n",
" 'path': 'test',\n",
" 'type': 'directory',\n",
" 'writable': True},\n",
" {'content': None,\n",
" 'created': '2018-01-26T19:40:51.357541Z',\n",
" 'format': None,\n",
" 'last_modified': '2018-01-26T19:40:51.357541Z',\n",
" 'mimetype': None,\n",
" 'name': 'Untitled.ipynb',\n",
" 'path': 'Untitled.ipynb',\n",
" 'type': 'notebook',\n",
" 'writable': True}],\n",
" 'created': '2018-02-01T23:27:27.433073Z',\n",
" 'format': 'json',\n",
" 'last_modified': '2018-02-01T23:27:27.433073Z',\n",
" 'mimetype': None,\n",
" 'name': '',\n",
" 'path': '',\n",
" 'type': 'directory',\n",
" 'writable': True}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.get('http://localhost:9090/services/hubshare/dir').json()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Response [403]>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.post('http://localhost:9090/services/hubshare/users/empty')\n",
"\n",
"# message from tornado ==> '_xsrf' argument missing from POST"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (hubshare)",
"language": "python",
"name": "hubshare"
},
"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.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment