-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathinsert_template.py
More file actions
39 lines (30 loc) · 1.41 KB
/
Copy pathinsert_template.py
File metadata and controls
39 lines (30 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pandas as pd
import requests
'''
Updates:
- 2021-02-04: Created the TestSample.csv file in the new data folder and added the path to it here . This way you don't have to create it yourself
Notes:
- If you run into a json-body not found error, than you forgot to configure the application/json mapping template in the method
- Some students had the problem: They get 200 here but the ClodWatch log of the Lambda says KeyError: 'context' -- I can only force this when I don't send in a payload to the API. Make sure you send data
- If you get 403 error: Make sure to add the resource name you created in API gateway to the URL . In my case "hello". If you just copy out your URL from the "stage" in the UI then this is missing.
'''
# URL of your endpoint
URL = "https://waz92zyjq7.execute-api.us-east-1.amazonaws.com/dev/main"
#read the testfile
data = pd.read_csv('Online_Retail_Cleaned_10rows.csv', sep = ',')
# write a single row from the testfile into the api
#export = data.loc[2].to_json()
#response = requests.post(URL, data = export)
#print(response)
# write all the rows from the testfile to the api as put request
for i in data.index:
try:
# convert the row to json
export = data.loc[i].to_json()
#send it to the api
response = requests.post(URL, data = export)
# print the return code
print(export)
print(response)
except:
print(data.loc[i])