Switch from urllib to requests to improve reliability (#867)

* Switch from urllib to requests to improve reliability

* Keep ruff linter-specific

* update

* update

* update
This commit is contained in:
Sebastian Raschka
2025-10-07 15:22:59 -05:00
committed by GitHub
parent 8552565bda
commit 7bd263144e
47 changed files with 592 additions and 436 deletions

View File

@@ -163,6 +163,30 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import requests\n",
"\n",
"if not os.path.exists(\"the-verdict.txt\"):\n",
" url = (\n",
" \"https://raw.githubusercontent.com/rasbt/\"\n",
" \"LLMs-from-scratch/main/ch02/01_main-chapter-code/\"\n",
" \"the-verdict.txt\"\n",
" )\n",
" file_path = \"the-verdict.txt\"\n",
"\n",
" response = requests.get(url, timeout=30)\n",
" response.raise_for_status()\n",
" with open(file_path, \"wb\") as f:\n",
" f.write(response.content)\n",
"\n",
"\n",
"# The book originally used the following code below\n",
"# However, urllib uses older protocol settings that\n",
"# can cause problems for some readers using a VPN.\n",
"# The `requests` version above is more robust\n",
"# in that regard.\n",
"\n",
"\"\"\"\n",
"import os\n",
"import urllib.request\n",
"\n",
@@ -171,7 +195,8 @@
" \"LLMs-from-scratch/main/ch02/01_main-chapter-code/\"\n",
" \"the-verdict.txt\")\n",
" file_path = \"the-verdict.txt\"\n",
" urllib.request.urlretrieve(url, file_path)"
" urllib.request.urlretrieve(url, file_path)\n",
"\"\"\""
]
},
{