@@ -27,7 +27,9 @@ def print_http_status(code, description):
27
27
"""Returns HTTP status code and description"""
28
28
if "100" <= code <= "103" :
29
29
print (f" | ✅ Status Test: { code } - { description } " )
30
- elif "200" <= code <= "299" :
30
+ elif "200" == code :
31
+ print (f" | 🆗 Status Test: { code } - { description } " )
32
+ elif "201" <= code <= "299" :
31
33
print (f" | ✅ Status Test: { code } - { description } " )
32
34
elif "300" <= code <= "600" :
33
35
print (f" | ❌ Status Test: { code } - { description } " )
@@ -103,7 +105,7 @@ def print_http_status(code, description):
103
105
}
104
106
105
107
JSON_GET_URL = "https://httpbin.org/get"
106
- STATUS_TEST = "https://httpbin.org/status/"
108
+ STATUS_TEST_URL = "https://httpbin.org/status/"
107
109
108
110
print (f"\n Connecting to { ssid } ..." )
109
111
print (f"Signal Strength: { rssi } " )
@@ -118,33 +120,33 @@ def print_http_status(code, description):
118
120
HEADERS = {"user-agent" : "blinka/1.0.0" }
119
121
120
122
print (f" | GET JSON: { JSON_GET_URL } " )
121
- response = requests .get (JSON_GET_URL , headers = HEADERS )
122
-
123
- json_data = response .json ()
124
- HEADERS = json_data ["headers" ]
125
- print (f" | User-Agent: { HEADERS ['User-Agent' ]} " )
126
-
127
- # HTTP STATUS CODE TESTING
128
- # https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
129
- STATUS_CODE = str (response .status_code )
130
- STATUS_DESCRIPTION = http_status_codes .get (STATUS_CODE , "Unknown Status Code" )
131
- print_http_status (STATUS_CODE , STATUS_DESCRIPTION )
132
- response .close ()
133
- print (f" | ✂️ Disconnected from { JSON_GET_URL } " )
134
- print (" | " )
135
-
136
- print (f" | Status Code Test: { STATUS_TEST } " )
137
- # Some return errors then confirm the error (that's a good thing)
138
- # Demonstrates not all errors have the same behavior
139
- # 300, 304, and 306 in particular
140
- for codes in sorted (http_status_codes .keys (), key = int ):
141
- status_test_url = STATUS_TEST + codes
142
- response = requests .get (status_test_url , headers = HEADERS )
143
- SORT_STATUS_CODE = str (response .status_code )
144
- SORT_STATUS_DESC = http_status_codes .get (SORT_STATUS_CODE , "Unknown Status Code" )
145
- print_http_status (SORT_STATUS_CODE , SORT_STATUS_DESC )
123
+ with requests .get (JSON_GET_URL , headers = HEADERS ) as response :
124
+ json_data = response .json ()
125
+ HEADERS = json_data ["headers" ]
126
+ print (f" | User-Agent: { HEADERS ['User-Agent' ]} " )
127
+
128
+ # HTTP STATUS CODE TESTING
129
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
130
+ STATUS_CODE = str (response .status_code )
131
+ STATUS_DESCRIPTION = http_status_codes .get (STATUS_CODE , "Unknown Status Code" )
132
+ print_http_status (STATUS_CODE , STATUS_DESCRIPTION )
146
133
response .close ()
147
-
148
- print (f" | ✂️ Disconnected from { JSON_GET_URL } " )
149
-
150
- print ("Finished!" )
134
+ print (f" | ✂️ Disconnected from { JSON_GET_URL } " )
135
+ print (" | " )
136
+
137
+ print (f" | Status Code Test: { STATUS_TEST_URL } " )
138
+ # Some return errors then confirm the error (that's a good thing)
139
+ # Demonstrates not all errors have the same behavior
140
+ # 300, 304, and 306 in particular
141
+ for codes in sorted (http_status_codes .keys (), key = int ):
142
+ header_status_test_url = STATUS_TEST_URL + codes
143
+ response = requests .get (header_status_test_url , headers = HEADERS )
144
+ SORT_STATUS_CODE = str (response .status_code )
145
+ SORT_STATUS_DESC = http_status_codes .get (
146
+ SORT_STATUS_CODE , "Unknown Status Code"
147
+ )
148
+ print_http_status (SORT_STATUS_CODE , SORT_STATUS_DESC )
149
+
150
+ print (f" | ✂️ Disconnected from { JSON_GET_URL } " )
151
+
152
+ print ("Finished!" )
0 commit comments