Skip to content

Commit

Permalink
Fix 403 error
Browse files Browse the repository at this point in the history
  • Loading branch information
patnr committed Feb 19, 2024
1 parent 08a2f45 commit 973f31d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r requirements.txt
jupytext
pre-commit
requests
13 changes: 7 additions & 6 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
from pathlib import Path
import subprocess
import sys
import urllib.request
import requests
from urllib.parse import unquote

from markdown import markdown as md2html


UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
ROOT = Path(__file__).parents[1]


Expand Down Expand Up @@ -63,13 +64,13 @@ def errm(issue):
# Internet links
if "http" in link:
try:
request = urllib.request.Request(
link, method="HEAD", headers={'User-Agent': 'Mozilla'})
response = urllib.request.urlopen(request, timeout=2)
assert response.status == 200
response = requests.head(link, headers={'User-Agent': UA})
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
assert response.status_code < 400
except Exception as e:
failed |= True
_report_error(errm("**requesting**") + f"\nError:\n {e}")
_report_error(errm("**requesting**") +
f"\nStatus code: {response.status_code}")

# Local links
else:
Expand Down

0 comments on commit 973f31d

Please sign in to comment.