Skip to content

Commit

Permalink
Fix %help web request
Browse files Browse the repository at this point in the history
  • Loading branch information
hugetim committed Oct 28, 2024
1 parent 79a34b1 commit 500761e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion nbs/09_magics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,9 @@
" html_base = \"https://www.stata.com\"\n",
" html_help = urllib.parse.urljoin(html_base, \"help.cgi?{}\")\n",
" url_safe_code = urllib.parse.quote(code)\n",
" reply = urllib.request.urlopen(html_help.format(url_safe_code))\n",
" 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",
" request = urllib.request.Request(html_help.format(url_safe_code), headers=headers)\n",
" reply = urllib.request.urlopen(request)\n",
" html = reply.read().decode(\"utf-8\")\n",
"\n",
" # Remove excessive extra lines (Note css: \"white-space: pre-wrap\")\n",
Expand Down
4 changes: 3 additions & 1 deletion nbstata/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ def _get_help_html(self, code):
html_base = "https://www.stata.com"
html_help = urllib.parse.urljoin(html_base, "help.cgi?{}")
url_safe_code = urllib.parse.quote(code)
reply = urllib.request.urlopen(html_help.format(url_safe_code))
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"}
request = urllib.request.Request(html_help.format(url_safe_code), headers=headers)
reply = urllib.request.urlopen(request)
html = reply.read().decode("utf-8")

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

0 comments on commit 500761e

Please sign in to comment.