-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalScript.py
More file actions
46 lines (36 loc) · 1.18 KB
/
Copy pathlocalScript.py
File metadata and controls
46 lines (36 loc) · 1.18 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
40
41
42
43
44
45
46
import requests
import json
from datetime import datetime
# Set the URL of the API endpoint to post data to
url = 'http://localhost:8000/milldata/devices/1/timestamps/'
# Set the data to be posted in JSON format
data = {
'data': str(datetime.timestamp(datetime.now())),
'initial_hold':600,
'circle':21,
'feed_time':6,
'circle_hold':15,
'galla_clear_time':20,
'actual_hold':900,
}
print(f"Data is {data} and data type is {type(data)}")
# Convert the data to JSON format
json_data = json.dumps(data)
print(f"JSON data is {json_data} and data type is {type(json)}")
# Set the headers for the POST request
headers = {
'Content-Type': 'application/json'
}
# Set the username and password for authentication
username = 'testuser1'
password = 'Test4work'
# Send the POST request to the API endpoint with authentication
response = requests.post(url, data=json_data, headers=headers, auth=(username, password))
# Check if the request was successful
if response.status_code == 201:
print("Data sent successfully")
else:
print("Failed to send data")
print(f"Status Code: {response.status_code}")
# Print the response from the API endpoint
print(response.content)