Skip to content

Commit 6db8f1e

Browse files
committed
Simple requests demo
1 parent b1b1455 commit 6db8f1e

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

Simple Requests Call.ipynb

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Simple Requests Demo\n",
8+
"\n",
9+
"This demo of multyvac with cloudpipe requests a remote URL, getting the status code and the server header"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {
16+
"collapsed": true
17+
},
18+
"outputs": [],
19+
"source": [
20+
"import multyvac\n",
21+
"import os"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 3,
27+
"metadata": {
28+
"collapsed": false
29+
},
30+
"outputs": [],
31+
"source": [
32+
"# Pulling the configuration\n",
33+
"multyvac.config.api_key = os.environ['MULTYVAC_API_KEY'] # Rackspace Username\n",
34+
"multyvac.config.api_secret_key = os.environ['MULTYVAC_API_SECRET_KEY'] # Rackspace API Key\n",
35+
"multyvac.config.api_url = \"https://cloudpipe.tmpnb.org/v1\""
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"metadata": {
42+
"collapsed": true
43+
},
44+
"outputs": [],
45+
"source": [
46+
"import requests\n",
47+
"\n",
48+
"def status(url):\n",
49+
" return requests.get(url).status_code\n",
50+
"\n",
51+
"def server_header(url):\n",
52+
" return requests.get(url).headers.get('server')"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 8,
58+
"metadata": {
59+
"collapsed": false
60+
},
61+
"outputs": [
62+
{
63+
"data": {
64+
"text/plain": [
65+
"200"
66+
]
67+
},
68+
"execution_count": 8,
69+
"metadata": {},
70+
"output_type": "execute_result"
71+
}
72+
],
73+
"source": [
74+
"jid = multyvac.submit(status, \"https://developer.rackspace.com\")\n",
75+
"multyvac.get(jid).get_result()"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 10,
81+
"metadata": {
82+
"collapsed": false
83+
},
84+
"outputs": [
85+
{
86+
"data": {
87+
"text/plain": [
88+
"'Nintendo WiiOS; Server 1.up'"
89+
]
90+
},
91+
"execution_count": 10,
92+
"metadata": {},
93+
"output_type": "execute_result"
94+
}
95+
],
96+
"source": [
97+
"jid = multyvac.submit(server_header, \"https://developer.rackspace.com\")\n",
98+
"multyvac.get(jid).get_result()"
99+
]
100+
}
101+
],
102+
"metadata": {
103+
"kernelspec": {
104+
"display_name": "Python 2",
105+
"language": "python",
106+
"name": "python2"
107+
},
108+
"language_info": {
109+
"codemirror_mode": {
110+
"name": "ipython",
111+
"version": 2
112+
},
113+
"file_extension": ".py",
114+
"mimetype": "text/x-python",
115+
"name": "python",
116+
"nbconvert_exporter": "python",
117+
"pygments_lexer": "ipython2",
118+
"version": "2.7.9"
119+
}
120+
},
121+
"nbformat": 4,
122+
"nbformat_minor": 0
123+
}

0 commit comments

Comments
 (0)