-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_code.py
28 lines (22 loc) 路 919 Bytes
/
status_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/102.0.5005.148 Safari/537.36',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
'application/signed-exchange;v=b3;q=0.9 '
}
url = 'http://keycloak.nixsolutions.com/auth'
print(f'Initial address: {url}')
req = requests.head(url=url, headers=headers)
redirect = None
if req.status_code == 301:
print(f'Server response: {req.status_code}')
try:
redirect = req.headers['Location']
print(redirect)
print(f'Redirect: {redirect}')
req = requests.get(url=redirect, headers=headers)
print(f'Server response: {req.status_code}')
except KeyError:
print('There is no redirect address')
print(f'Server response: {req.status_code}')