I'm trying to make a custom script that will send a request to the page and test it for availability, if the answer is 200, then I want the answer to be 1, if any other 2, and the metric will not be recorded, tell me how best to do it? Sorry if this is a stupid question, I'm just learning python
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import os
import datetime
import pytz
def get_status_ghe():
url_list = [os.environ.get('http://testurl.com:8080')]
for i in range(0, len(url_list)):
if resp.status_code == 200:
print('ghe0')
elif resp.status_code != 200:
print('ghe1')
else:
print('ghe2')
def ghe_request():
try:
resp = requests.head('http://testurl.com:8080')
if resp.status_code == 200:
return 1
print(resp)
print('1')
else:
return 0
print(resp)
print('0')
except:
return 0
forloop is missing the call torequests.head.print()calls afterreturnwill execute, sincereturnexits the function. Movereturnafter the print statements.http://testurl.com:8080really the name of your environment variable? It looks more like the value.ghe2?