You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -115,12 +115,12 @@ Example of reading URL parameters:
115
115
curl https://myfunc/user/?id=1
116
116
```
117
117
118
-
Will fill the event with the following parameters:
118
+
will fill the event with the following parameters:
119
119
```python
120
120
event['path'] ="/user/"
121
121
122
122
event['queryStringParameters'] = {
123
-
"id": "1"
123
+
"id": "1"
124
124
}
125
125
```
126
126
@@ -130,8 +130,8 @@ CRON jobs share the same pattern as HTTP calls. You can find the information pas
130
130
131
131
```python
132
132
defhandle(event, context):
133
-
cron_body = event['body']
134
-
# ...
133
+
cron_body = event['body']
134
+
# ...
135
135
```
136
136
137
137
### Connecting to HTTP services in Python
@@ -150,20 +150,20 @@ auth_token=os.getenv('X-AUTH-TOKEN') # You can pass tokens through os environmen
150
150
url={YOURURL} # If you want a dynamic URL based on information sent to handle(), define the URL inside the function
151
151
152
152
defhandle(event, context):
153
-
req = request.Request(url, method='GET')
154
-
req.add_header('X-Auth-Token',auth_token)
155
-
try:
153
+
req = request.Request(url, method='GET')
154
+
req.add_header('X-Auth-Token',auth_token)
155
+
try:
156
156
res = request.urlopen(req).read().decode()
157
-
except error.HTTPError as e:
158
-
res = e.read().decode()
157
+
except error.HTTPError as e:
158
+
res = e.read().decode()
159
159
160
-
return {
161
-
"body": json.loads(res),
162
-
"headers": {
163
-
"Content-Type": ["application/json"],
164
-
},
165
-
"statusCode": 200,
166
-
}
160
+
return {
161
+
"body": json.loads(res),
162
+
"headers": {
163
+
"Content-Type": ["application/json"],
164
+
},
165
+
"statusCode": 200,
166
+
}
167
167
```
168
168
169
169
**`POST` request example**
@@ -194,18 +194,6 @@ def handle(event, context):
194
194
},
195
195
"statusCode": 200,
196
196
}
197
-
try:
198
-
res = request.urlopen(req).read().decode()
199
-
except error.HTTPError as e:
200
-
res = e.read().decode()
201
-
202
-
return {
203
-
"body": json.loads(res),
204
-
"headers": {
205
-
"Content-Type": ["application/json"],
206
-
},
207
-
"statusCode": 200,
208
-
}
209
197
```
210
198
<Messagetype="note">
211
199
To use other libraries like `request`, you need to upload your project [with advanced methods](/serverless-functions/reference-content/deploy-function/) (recommended)
0 commit comments