Beautiful Soup - urllib.error.HTTPError: HTTP Error 403: Forbidden

Roy Sukrit

I am trying to download a GIF file with urrlib, but it is throwing this error:

urllib.error.HTTPError: HTTP Error 403: Forbidden

This does not happen when I download from other blog sites. This is my code:

import requests
import urllib.request

url_1 = 'https://goodlogo.com/images/logos/small/nike_classic_logo_2355.gif'

source_code = requests.get(url_1,headers = {'User-Agent': 'Mozilla/5.0'})    

path = 'C:/Users/roysu/Desktop/src_code/Python_projects/python/web_scrap/myPath/'

full_name = path + ".gif"    
urllib.request.urlretrieve(url_1,full_name)
Sushil

Don't use urllib.request.urlretrieve. Instead, use the requests library like this:

import requests

url = 'https://goodlogo.com/images/logos/small/nike_classic_logo_2355.gif'

path = "D:\\Test.gif"

response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})

file = open(path, "wb")

file.write(response.content)

file.close()

Output:

enter image description here

Hope that this helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

urllib.error.HTTPError: HTTP Error 403: Forbidden for urlretrieve

urllib2.HTTPError: HTTP Error 403: Forbidden

urllib2.HTTPError: HTTP Error 403: Forbidden

urllib.error.HTTPError: HTTP Error 403: Forbidden with urllib.requests

Python 3.6.2 url.request.urlopen() urllib.error.HTTPError: HTTP Error 403: Forbidden

urllib.error.HTTPError: HTTP Error 403: Forbidden in my web scrapping

JSON from webpage into Python script: urllib.error.HTTPError: HTTP Error 403: Forbidden

HTTPError: HTTP Error 403: Forbidden on Google Colab

torchvision MNIST HTTPError: HTTP Error 403: Forbidden

raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbidden

bokeh sample data download fail with 'HTTPError: HTTP Error 403: Forbidden'

Web Scraping getting error (HTTP Error 403: Forbidden) using urllib

gTTS HTTPError: 403 Client Error: Forbidden for url

python urllib.request http error 403: forbidden

HTTP Error 403: Forbidden while downloading file using urllib

urllib2 Error 403: Forbidden

HTTP Error 403: Forbidden with urlretrieve

Pytube error: urllib.error.HTTPError: HTTP Error 404: Not Found

download image from url using python urllib but receiving HTTP Error 403: Forbidden

urllib.error.HTTPError: HTTP Error 503: Service Unavailable python

Pytube : urllib.error.HTTPError: HTTP Error 410: Gone

Again urllib.error.HTTPError: HTTP Error 400: Bad Request

Python: urllib.error.HTTPError: HTTP Error 404: Not Found

Python urllib.error.HTTPError: HTTP Error 404: Not Found

urllib.error.HTTPError: HTTP Error 502: Bad Gateway PYTHON

urllib.error.HTTPError: HTTP Error 404: Not Found

urllib.error.HTTPError: HTTP Error 404: Not Found yfinance library

open_http: 403 Forbidden (OpenURI::HTTPError)

Python 3.5 urllib.request 403 Forbidden Error