When you do import urllib.request
you are not actually importing the requests
package that you installed, instead you are just using the request
module of the builtin urllib
package. You should do import requests
instead. You can find the requests
package docs here. Here is some sample code to download a file
import requests
url = 'http://example.com/image.png'
r = requests.get(url)
with open("image.png", "wb") as image:
image.write(r.content)
Also your output shows Operation timed out
as the error, that's usually a network related issue.
Since you asked, this is how to write your code sample using requests:
import requests
start = int(input("Start range: "))
stop = int(input("End range: "))
for i in range(start, stop+1):
filename = str(i).rjust(6, '0')+".jpg"
url = 'https://website.com/Image_' + filename
print(url)
r = requests.get(url)
with open(filename, "wb") as image:
image.write(r.content)