I am getting the following error
AttributeError: 'str' object has no attribute 'status_code'
I am getting data through a API, and when the API is down the value is "down"
@app.route('/test_api')
def test_api():
ipno = "192.168.0.120"
port = "8060"
url_time = 'https://{}:{}/time/'.format(ipno, port)
url_member = 'https://{}:{}/member/'.format(ipno, port)
url_state = 'https://{}:{}/state/'.format(ipno, port)
if url_time.status_code == requests.codes.ok:
r_time = _session.get(url_time).content
else:
r_time = "Time is down"
if url_member.status_code == requests.codes.ok:
r_member = _session.get(url_member).content
else:
r_member = "Member is down"
if url_state.status_code == requests.codes.ok:
r_state = _session.get(url_state).content
else:
r_state = "State is down"
return render_template('test_api.html', time = json.loads(r_time), member=json.loads(r_member), state=json.loads(r_state))
You're not making the actual request using the requests library:
url_time = 'https://{}:{}/time/'.format(ipno, port)
time_request = requests.get(url_time)
if time_request.status_code == requests.codes.ok:
r_time = _session.get(url_time).content