Closed clairenied15 closed 5 years ago
Claire, your call_status_patient.py
file is empty on GitHub, so I cannot check that. Please push it up.
I just pushed it to the "validation" branch.
In hr_server.py
, the function tachycardia
is called when you make a request to /api/status/patient
, The first line of this function is r=request.get_json()
. But, in call_status_patient.py
, your function call_status
sends a GET request without a JSON. So, the tachycardia
function puts a NONE into the variable r. When you then try to to run the code age=r["user_age"]
, you get an error because NONE does not have subscripts.
So, you need to send a JSON with the GET request. In call_status_patient.py
and the call_status
function, define a dictionary that contains key/value pairs for user_age and heart_rate. Then, modify the GET request as follows:
r = requests.get("http://127.0.0.1:5000/api/status/patient", json=my_dict)
where my_dict
is the dictionary you created. Then, give it a try.
I'll tell you now then you will get another error. In the tachycardia
function in hr_server.py
, you return a text string. In your call_status
function, you have the code answer=r.json()
. But, your server doesn't return a json, it only returns a string. So, you will get an error. Change the code to be answer=r.text
and you should see the appropriate result.
Give this a try and let me know if you have any further questions.
I tried doing the things you said above but am now getting an error in call_status_patient.py in my line "answer = r.text()". It is saying "str object is not callable".
Here is where parsing the error string can help. It says str object is not callable
. When you call a function, you put ()
after the name, even if there are not parameters. The ()
indicates you are calling something. So, the error is saying that answer=r.text()
has a str
or string that you are trying to call but shouldn't.
The request
object r
has a property .text
. It is a string property. When you put ()
after it, you are then trying to make a string callable, which it is not. Hence, the error.
Note that .text
is a property or attribute of the object r
. However, .json()
is a method or function of the object r
. Hence, it needs the ()
to call it. .text
does not.
Does that make sense?
Yes, thank you!
I am trying to see how my code for the /api/status/patient part is working but I think there is an error in line 34 of hr_server.py. I also wrote the call_status_patient.py to see the output of the /api/status/patient but I'm not sure that I did that correctly. Basically, I'm having trouble seeing what this part of the server is doing and where it is breaking. I think there are problems with "age = r["user_age"]" and I'm not sure why.