0

y is the url http://statseeker/graphs/ping.jc-4050-1.delay.1405951106.png. This is a internal website. When trying to save this PNG file this is the error it throws. I have not been able to find any info of even where to start. I want to be able to save it as whatever I want.

Someone please advise. I have asked many questions on here any almost all go unanswered. I don't know where else to turn.

data1 = urllib2.urlopen(y).read()
    g = 'test.png'
    urllib2.urlopen(data1).write(g)

Output

http://statseeker/graphs/ping.jc-4050-1.delay.1405951106.png
    Traceback (most recent call last):
      File "JacksonShowAndSave1.py", line 46, in <module>
        urllib2.urlopen(data1).write(g)
      File "C:\Python27\lib\urllib2.py", line 127, in urlopen
        return _opener.open(url, data, timeout)
      File "C:\Python27\lib\urllib2.py", line 396, in open
        protocol = req.get_type()
      File "C:\Python27\lib\urllib2.py", line 258, in get_type
        raise ValueError, "unknown url type: %s" % self.__original
    ValueError: unknown url type: ëPNG
BilliAm
  • 590
  • 2
  • 6
  • 26

1 Answers1

1

Since I have asked this three times and can not even get one answer. I tried myself with a little more detail and was able to solve this.

Correct:

y = http://img1.wikia.nocookie.net/__cb20090805033855/zelda/images/5/56/Link_Artwork_7_(The_Minish_Cap).png
link = urllib2.Request(y)
response = urllib2.urlopen(link)
output = open('out2.jpg','wb')
output.write(response.read())
output.close()

Worked Perfectly.

Apparently urllib2 can NOT open ANY image files in the format of directly opening and reading a image.

EDIT: This did not work because originally I was not using 'wb' as the read from and write to statements.

Incorrect:

data1 = urllib2.urlopen(y).read()
    g = 'test.png'
    urllib2.urlopen(data1).write(g)
BilliAm
  • 590
  • 2
  • 6
  • 26