· 5 years ago · Aug 13, 2020, 06:44 AM
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "Get Requests\n"
8 ]
9 },
10 {
11 "cell_type": "code",
12 "execution_count": 1,
13 "metadata": {},
14 "outputs": [],
15 "source": [
16 "#facebook\n",
17 "import requests\n",
18 "facebook_id=85\n",
19 "url= \"http://graph.facebook.com/{}/picture?type=large\".format(facebook_id)\n",
20 "r=requests.get(url)\n",
21 "with open(\"picture.jpg\",\"wb\") as file:\n",
22 " file.write(r.content)"
23 ]
24 },
25 {
26 "cell_type": "code",
27 "execution_count": 2,
28 "metadata": {},
29 "outputs": [
30 {
31 "name": "stdout",
32 "output_type": "stream",
33 "text": [
34 "{\n",
35 " \"error_message\" : \"You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account\",\n",
36 " \"results\" : [],\n",
37 " \"status\" : \"REQUEST_DENIED\"\n",
38 "}\n",
39 "\n"
40 ]
41 }
42 ],
43 "source": [
44 "#googlemaps\n",
45 "url= \"https://maps.googleapis.com/maps/api/geocode/json\"\n",
46 "parameters={\n",
47 " \"address\" : \"NIT,Rourkela\"\n",
48 "}\n",
49 "r=requests.get(url,params=parameters)\n",
50 "print(r.content.decode('UTF-8'))"
51 ]
52 },
53 {
54 "cell_type": "markdown",
55 "metadata": {},
56 "source": [
57 "Post Requests\n"
58 ]
59 },
60 {
61 "cell_type": "code",
62 "execution_count": 3,
63 "metadata": {},
64 "outputs": [],
65 "source": [
66 "#pastebin API\n",
67 "import requests"
68 ]
69 },
70 {
71 "cell_type": "code",
72 "execution_count": 4,
73 "metadata": {},
74 "outputs": [],
75 "source": [
76 "key= \"TXs3jJiC_41cEm8sAof3sbUQu4rfMwyD\""
77 ]
78 },
79 {
80 "cell_type": "code",
81 "execution_count": 5,
82 "metadata": {},
83 "outputs": [],
84 "source": [
85 "url=\"https://pastebin.com/api/api_post.php\"\n"
86 ]
87 },
88 {
89 "cell_type": "code",
90 "execution_count": 6,
91 "metadata": {},
92 "outputs": [],
93 "source": [
94 "data={\n",
95 " \"api_dev_key\": key,\n",
96 " \"api_option\":\"paste\",\n",
97 " \"api_paste_code\":\"Hello, How re you?\"\n",
98 "}"
99 ]
100 },
101 {
102 "cell_type": "code",
103 "execution_count": 7,
104 "metadata": {},
105 "outputs": [],
106 "source": [
107 "response=requests.post(url,data=data)"
108 ]
109 },
110 {
111 "cell_type": "code",
112 "execution_count": 8,
113 "metadata": {},
114 "outputs": [
115 {
116 "data": {
117 "text/plain": [
118 "b'https://pastebin.com/WAkXd9zc'"
119 ]
120 },
121 "execution_count": 8,
122 "metadata": {},
123 "output_type": "execute_result"
124 }
125 ],
126 "source": [
127 "response.content"
128 ]
129 },
130 {
131 "cell_type": "code",
132 "execution_count": 9,
133 "metadata": {},
134 "outputs": [
135 {
136 "ename": "SyntaxError",
137 "evalue": "invalid syntax (<ipython-input-9-3f4491bbf16c>, line 6)",
138 "output_type": "error",
139 "traceback": [
140 "\u001b[1;36m File \u001b[1;32m\"<ipython-input-9-3f4491bbf16c>\"\u001b[1;36m, line \u001b[1;32m6\u001b[0m\n\u001b[1;33m \"api_paste_format\":\"python\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
141 ]
142 }
143 ],
144 "source": [
145 "with open(\"Web API\", \"r\") as file:\n",
146 " data={\n",
147 " \"api_dev_key\": key,\n",
148 " \"api_option\":\"paste\",\n",
149 " \"api_paste_code\":file.read()\n",
150 " \"api_paste_format\":\"python\"\n",
151 " \n",
152 " }\n",
153 " response= requests.post(url.data=data)\n",
154 " print(response.content)"
155 ]
156 },
157 {
158 "cell_type": "code",
159 "execution_count": null,
160 "metadata": {},
161 "outputs": [],
162 "source": []
163 }
164 ],
165 "metadata": {
166 "kernelspec": {
167 "display_name": "Python 3",
168 "language": "python",
169 "name": "python3"
170 },
171 "language_info": {
172 "codemirror_mode": {
173 "name": "ipython",
174 "version": 3
175 },
176 "file_extension": ".py",
177 "mimetype": "text/x-python",
178 "name": "python",
179 "nbconvert_exporter": "python",
180 "pygments_lexer": "ipython3",
181 "version": "3.7.6"
182 }
183 },
184 "nbformat": 4,
185 "nbformat_minor": 4
186}
187