0

I try to download a .tiff file from NASA. When doing it in the browser it works out fine. When trying it with the following python code

import urllib
f = urllib.FancyURLopener()
url = "https://neo.sci.gsfc.nasa.gov/servlet/RenderData?si=1696692&cs=gs&format=TIFF&width=3600&height=1800"
f.retrieve(url, "test.TIFF")

I get the error

IOError: [Errno socket error] [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)

I found one similar question here solving the error by creating a new SSLContext. However I can not figure out how to save a downloaded file as required in my case.

Community
  • 1
  • 1
Oliver Wilken
  • 2,654
  • 1
  • 24
  • 34

2 Answers2

1

This seems to work:

from urllib.request import urlretrieve
url = 'https://neo.sci.gsfc.nasa.gov/servlet/RenderData?si=1696692&cs=gs&format=TIFF&width=3600&height=1800'
urlretrieve(url, 'result.TIFF')

Not sure if this will work in Python 2. Will update my answer later.

Eldin
  • 43
  • 4
1

I found a solution with python 2 using urllib2 that works for me:

import urllib2
url = "https://neo.sci.gsfc.nasa.gov/servlet/RenderData?si=1696692&cs=gs&format=TIFF&width=3600&height=1800"
f = urllib2.urlopen(url)
data = f.read()
with open("img.TIFF", "wb") as imgfile:
    imgfile.write(data)
Oliver Wilken
  • 2,654
  • 1
  • 24
  • 34