(Nov-07-2023, 12:36 PM)snippsat Wrote: Use Requests for this.
import requests url = "https://data.pr4e.org/romeo.txt" response = requests.get(url) print(response.status_code) print(response.text.strip()) # Download the file with open('romeo.txt', 'wb') as fp: fp.write(response.content)
Output:200 But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief
For some bizarre reason, I am getting the same result... any ideas?
import requests url = "https://data.pr4e.org/romeo.txt" response = requests.get(url) print(response.status_code) print(response.text.strip()) # Download the file with open('romeo.txt', 'wb') as fp: fp.write(response.content)
Error:Traceback (most recent call last):
File "/Users/Documents/pyfe/ex_12_01/test2.py", line 1, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 13, in <module>
from . import exceptions
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 7, in <module>
from http.client import IncompleteRead as httplib_IncompleteRead
ModuleNotFoundError: No module named 'http.client'; 'http' is not a package