Skip to content

Instantly share code, notes, and snippets.

@minrk
Created February 7, 2018 15:20
Show Gist options
  • Save minrk/89edb67ccde36ad6fbc0e057acf95fbd to your computer and use it in GitHub Desktop.
Save minrk/89edb67ccde36ad6fbc0e057acf95fbd to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import os\nfrom subprocess import Popen\n\nenv = os.environ.copy()\nenv['JUPYTER_TOKEN'] = 'secret'\np = Popen(['jupyter', 'notebook', '--port=9999'], env=env)",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import requests\ns = requests.Session()\ns.headers['Authorization'] = 'token secret'",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "s.get('http://127.0.0.1:9999/api/contents/empty').json()",
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "{'content': [{'content': None,\n 'created': '2017-06-20T16:03:32Z',\n 'format': None,\n 'last_modified': '2017-06-20T16:03:32Z',\n 'mimetype': None,\n 'name': 'broken',\n 'path': 'empty/broken',\n 'type': 'file',\n 'writable': False},\n {'content': None,\n 'created': '2018-01-04T17:17:02.838623Z',\n 'format': None,\n 'last_modified': '2018-01-03T10:47:34Z',\n 'mimetype': 'text/plain',\n 'name': 'newtext.txt',\n 'path': 'empty/newtext.txt',\n 'type': 'file',\n 'writable': True},\n {'content': None,\n 'created': '2018-02-01T11:58:19.027866Z',\n 'format': None,\n 'last_modified': '2018-02-01T11:58:19.027866Z',\n 'mimetype': None,\n 'name': 'Untitled3.ipynb',\n 'path': 'empty/Untitled3.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2017-06-20T16:03:32Z',\n 'format': None,\n 'last_modified': '2017-06-20T16:03:32Z',\n 'mimetype': None,\n 'name': 'ok',\n 'path': 'empty/ok',\n 'type': 'directory',\n 'writable': True},\n {'content': None,\n 'created': '2017-11-28T16:59:13.120256Z',\n 'format': None,\n 'last_modified': '2017-11-28T13:28:53Z',\n 'mimetype': None,\n 'name': 'inorder.ipynb',\n 'path': 'empty/inorder.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2018-01-24T17:02:14.486603Z',\n 'format': None,\n 'last_modified': '2018-01-23T17:37:11Z',\n 'mimetype': None,\n 'name': 'Untitled2.ipynb',\n 'path': 'empty/Untitled2.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2017-12-12T09:05:18.694326Z',\n 'format': None,\n 'last_modified': '2017-12-07T14:55:21Z',\n 'mimetype': None,\n 'name': 'sql.ipynb',\n 'path': 'empty/sql.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2018-02-07T15:18:06.556079Z',\n 'format': None,\n 'last_modified': '2018-02-07T15:18:06.556079Z',\n 'mimetype': None,\n 'name': 'nbtoken.ipynb',\n 'path': 'empty/nbtoken.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2018-01-31T21:26:35.103768Z',\n 'format': None,\n 'last_modified': '2018-01-31T14:26:20Z',\n 'mimetype': None,\n 'name': 'kernel-restart-problem.ipynb',\n 'path': 'empty/kernel-restart-problem.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2018-01-24T17:02:14.486349Z',\n 'format': None,\n 'last_modified': '2018-01-24T13:25:21Z',\n 'mimetype': None,\n 'name': 'polite-errors.ipynb',\n 'path': 'empty/polite-errors.ipynb',\n 'type': 'notebook',\n 'writable': True},\n {'content': None,\n 'created': '2018-02-02T13:36:07.737049Z',\n 'format': None,\n 'last_modified': '2018-02-02T13:36:07.737049Z',\n 'mimetype': None,\n 'name': 'test.ipynb',\n 'path': 'empty/test.ipynb',\n 'type': 'notebook',\n 'writable': True}],\n 'created': '2018-02-07T15:18:06.556523Z',\n 'format': 'json',\n 'last_modified': '2018-02-07T15:18:06.556523Z',\n 'mimetype': None,\n 'name': 'empty',\n 'path': 'empty',\n 'type': 'directory',\n 'writable': True}"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "s.post('http://127.0.0.1:9999/api/contents/empty')",
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 6,
"data": {
"text/plain": "201 http://127.0.0.1:9999/api/contents/empty\nheaders: Access-Control-Allow-Origin: \n Content-Length: 221\n Content-Security-Policy: frame-ancestors 'self'; report-uri /api/security/csp-report; default-src 'none'\n Content-Type: application/json\n Date: Wed, 07 Feb 2018 15:18:20 GMT\n Last-Modified: Wed, 07 Feb 2018 15:18:20 GMT\n Location: /api/contents/empty/untitled\n Server: TornadoServer/4.5.3\n Set-Cookie: username-127-0-0-1-9999=\"2|1:0|10:1518016700|23:username-127-0-0-1-9999|44:ZDdmMGJlZWM1OWE2NGFjNGJjMWQ2OTgwM2M1OGNlZTk=|2f9948ce53d29e73c1aa2e2fc62736829825c160529e73c15c8710fd7d863a1a\"; expires=Fri, 09 Mar 2018 15:18:20 GMT; HttpOnly; Path=/\n\nbody (application/json):\n{'content': None,\n 'created': '2018-02-07T15:18:20.378483Z',\n 'format': None,\n 'last_modified': '2018-02-07T15:18:20.378483Z',\n 'mimetype': None,\n 'name': 'untitled',\n 'path': 'empty/untitled',\n 'type': 'file',\n 'writable': True}"
},
"metadata": {}
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.4",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment