API looks like this
app = Flask(__name__)
@app.route('/mycalculator', methods = ['POST'])
def json_example():
req_data = request.get_json()
#..... did a bunch of computation
return response
My API testing code look like:
import requests
import json
URL = "http://127.0.0.1:5000/mycalculator/"
def test_jsonget_guideline():
file = open('myjsonfile', 'r')
json_input = file.read()
request_json = json.loads(json_input)
print(request_json)
# make post request within json input body
response = requests.post(url=URL,
data=request_json)
if response.ok:
print(response.content)
else:
print("response not okay. status code: {}".format(response.status_code))
I keep getting the error like this:
status code: 403
I was able to test this JSON file using Postman. But I want to write a python script to automate all the testings. Anyone know which step I am not doing right? I looked through many tutorial videos, but I was not able to fix this problem. I would greatly appreciate your help!