0

I downloaded an image using python urllib library and the image is downloaded but when I try to open it it says "we dont support this extension" in default image software even though I downloaded image as png. I tried this on multiple url but the result is always the same.

import urllib.request

def download_image(url):

    full_name = "img3.png"
    urllib.request.urlretrieve(url, full_name)


download_image("https://en.wikipedia.org/wiki/File:Google.png")
aloisdg
  • 22,270
  • 6
  • 85
  • 105
  • Possible duplicate of [Downloading a picture via urllib and python](https://stackoverflow.com/questions/3042757/downloading-a-picture-via-urllib-and-python) – aloisdg Sep 10 '19 at 08:33

1 Answers1

0

It is not working because you are not pointing to an image. You are trying to download an html page as a png. Change the url to a png and it will work.

import urllib.request

def download_image(url):

    full_name = "img3.png"
    urllib.request.urlretrieve(url, full_name)


download_image("https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Google.png/800px-Google.png")
aloisdg
  • 22,270
  • 6
  • 85
  • 105
  • Thank you for pointing the mistake but I dont know how to do that. I copied the url of an image – Muhammad Ahmed Sep 10 '19 at 08:46
  • Thanks. Turns out it was my mistake even though I copied the image url from the web page I had to copy that image url again. – Muhammad Ahmed Sep 10 '19 at 09:16
  • @MuhammadAhmed Glad you figure it out. If this answer solved your problem, [mark it as answered](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – aloisdg Sep 10 '19 at 10:04