Python Forum
HTTPError: Forbidden when try download image
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTPError: Forbidden when try download image
#9
(Jan-21-2017, 10:03 AM)snippsat Wrote: @scriptso you write a little messy Wink You are right that setting user-agent header can solve it for urllib. But the clear message is that urllib should not be used,when we have Requests. Can fix urlretrieve() bye using opener.retrieve(). That can take user-agent header.
>>> import urllib.request >>> img = 'https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-293122.jpg' >>> urllib.request.urlretrieve(img, '1.jpg') Traceback (most recent call last):   urllib.error.HTTPError: HTTP Error 403: Forbidden >>> # Fix it >>> opener = urllib.request.FancyURLopener({}) >>> opener.version = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.69 Safari/537.36' >>> opener.retrieve(img, '1.jpg') ('1.jpg', <http.client.HTTPMessage object at 0x038F2210>)

LMAO ! I get that a lot =( .... product of insomnia + scatter brain ... good stuff! I totally mixed up your fix and the original poster... maybe it is time for sleep X_x I 'durped' that up. *sigh*
Reply


Messages In This Thread
RE: HTTPError: Forbidden when try download image - by scriptso - Jan-21-2017, 12:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  403 Forbidden Error Evil_Patrick 1 4,488 Jun-20-2020, 02:19 PM
Last Post: snippsat
  urllib.error.HTTPError: HTTP Error 404: Not Found ckkkkk 4 8,830 Mar-03-2020, 11:30 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020