Skip to content

Commit 500761e

Browse files
committed
Fix %help web request
1 parent 79a34b1 commit 500761e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

nbs/09_magics.ipynb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,9 @@
10271027
" html_base = \"https://www.stata.com\"\n",
10281028
" html_help = urllib.parse.urljoin(html_base, \"help.cgi?{}\")\n",
10291029
" url_safe_code = urllib.parse.quote(code)\n",
1030-
" reply = urllib.request.urlopen(html_help.format(url_safe_code))\n",
1030+
" headers = {\"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\"}\n",
1031+
" request = urllib.request.Request(html_help.format(url_safe_code), headers=headers)\n",
1032+
" reply = urllib.request.urlopen(request)\n",
10311033
" html = reply.read().decode(\"utf-8\")\n",
10321034
"\n",
10331035
" # Remove excessive extra lines (Note css: \"white-space: pre-wrap\")\n",

nbstata/magics.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ def _get_help_html(self, code):
362362
html_base = "https://www.stata.com"
363363
html_help = urllib.parse.urljoin(html_base, "help.cgi?{}")
364364
url_safe_code = urllib.parse.quote(code)
365-
reply = urllib.request.urlopen(html_help.format(url_safe_code))
365+
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}
366+
request = urllib.request.Request(html_help.format(url_safe_code), headers=headers)
367+
reply = urllib.request.urlopen(request)
366368
html = reply.read().decode("utf-8")
367369

368370
# Remove excessive extra lines (Note css: "white-space: pre-wrap")

0 commit comments

Comments
 (0)