Skip to content

Commit ec9883e

Browse files
authored
Added support for headers to avoid HTTP error 403 (#32)
* Added support for headers to avoid HTTP error 403 Signed-off-by: Savitoj Singh <[email protected]> * Dynamic dist version in headers - #32 Signed-off-by: Savitoj Singh <[email protected]> Co-authored-by: Savitoj Singh <[email protected]>
1 parent 278f9ed commit ec9883e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

linkstatus/linkstatus.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from shutil import get_terminal_size
44

55
import click
6+
import pkg_resources
67
import requests
78

89
from linkstatus.parser import link_validator
@@ -20,11 +21,13 @@ def link_status(link, timeout=5):
2021
Returns:
2122
tuple of status (bool) and status code
2223
"""
23-
24+
headers = {
25+
"User-Agent": "linkstatus/{}".format(pkg_resources.get_distribution("linkstatus").version)
26+
}
2427
try:
25-
status_code = requests.get(link, timeout=timeout).status_code
28+
status_code = requests.get(link, headers=headers, timeout=timeout).status_code
2629
except requests.exceptions.SSLError:
27-
status_code = requests.get(link, verify=False, timeout=timeout).status_code
30+
status_code = requests.get(link, verify=False, headers=headers, timeout=timeout).status_code
2831
except Exception: # noqa
2932
# TODO: include exception in logging
3033
status_code = None

0 commit comments

Comments
 (0)