Skip to content

Commit

Permalink
Add a user agent and use requests error checking (#24)
Browse files Browse the repository at this point in the history
Fixes github blocking
  • Loading branch information
sciencewhiz authored Nov 21, 2024
1 parent 2da7219 commit 5444167
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sphinxext/remoteliteralinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import sys
import warnings

from difflib import unified_diff

from docutils import nodes
Expand Down Expand Up @@ -62,14 +63,13 @@ def read_file(self, url, location=None):
# try:
# with codecs.open(url, 'r', self.encoding, errors='strict') as f: # type: ignore # NOQA
# text = f.read() # type: unicode
response = requests.get(url)
response = requests.get(
url, headers={"User-Agent": "sphinxext-remoteliteralinclude"}
)
text = response.text

if text:
if not response.status_code == requests.codes.ok:
raise ValueError(
"HTTP request returned error code %s" % response.status_code
)
response.raise_for_status()

if "tab-width" in self.options:
text = text.expandtabs(self.options["tab-width"])
Expand Down

0 comments on commit 5444167

Please sign in to comment.