-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestserver.py
More file actions
60 lines (43 loc) · 1.53 KB
/
testserver.py
File metadata and controls
60 lines (43 loc) · 1.53 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from flask import Flask, jsonify, request, Response
from flask_cors import CORS, cross_origin
import requests
import json
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.before_request
def basic_authentication():
if request.method.lower() == 'options':
return Response()
@app.route("/api/feed", methods=['GET', 'POST'])
@cross_origin(allow_headers=['Content-Type'])
def handle_request():
# Define the URL and JSON payload
#url = "http://10.43.12.121:5000/"
#payload = {"request": "Left"}
# response = jsonify({'request': input['request']})
input = request.get_json()
print(input['request'])
if (input['request'] == "Left"):
return jsonify({'request': "cat-success"})
elif (input['request'] == "Right"):
return jsonify({'request': "dog-success"})
elif (input['request'] == "feed-data"):
return jsonify({'request': "data-success"})
else:
response = jsonify({'request': "error"})
response.status_code = 400
return response
if __name__ == '__main__':
app.run(debug=True, port=5000)
# # Define the URL and JSON payload
# url = "http://10.43.12.121:5000/"
# payload = {"request": "Left"}
# # Convert the payload to JSON
# json_payload = json.dumps(payload)
# # Set the content type header to JSON
# headers = {"Content-Type": "application/json"}
# # Send the POST request with the JSON payload
# response = requests.post(url, data=json_payload, headers=headers)
# # Print the response
# print(response.text)