NASA Imagery V1 (Python)

The next NASA open API that I wanted to play with is “Imagery” ( which retrieves a Landsat 8 image for a supplied location. I created a program but so far it is not working as expected.



#NASA Earth Imagery

#Modules to import

import json, requests

#Variables to use

#float – Latitude


#float – Longitude


#float – width and height of image in degress, default is 0.025


#YYYY-MM-DD format.


#string – API Key – provided free by





print(‘Hi and welcome to GeekTechStuff\’s NASA Earth Image searcher’)


year=input(‘Please enter a year in YYYY format, e.g. 2018:’)

month=input(‘Please enter a month in MM format, e.g. 03 for March:’)

day=input(‘Please enter a numerical day in DD format, i.e. 01 to 31:’)



lat=input(‘Please input latitude co-ordinates:’)

lon=input(‘Please input longitude co-ordinates:’)

#Request JSON

headers={‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6’}









However, my code fails. Time to debug it;

At first I got the error message:

Traceback (most recent call last):

  File “/Users/gary/Documents/”, line 44, in <module>


  File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/”, line 935, in raise_for_status

    raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:

I tried removing the response.raise_for_status() and this got me a different error message:

{‘error’: {‘code’: ‘HTTPS_REQUIRED’, ‘message’: ‘Requests must be made over HTTPS. Try accessing the API at:;}}

From the look of it my Python code is sending the URL request over HTTP instead of HTTPS. I added in some headers just in case the NASA API site was expecting a web browser to be making the response. Same issue,

I checked to see if my MacBook had done any recent updates – not in recent weeks.

I tried some of my other recent Python programs that utilise HTTPS – they work.

I reinstalled the SSL certificates that Python uses (via Applications/Python 3.6/Install Certificates.command) and then reran my program – same issue.

I’ll continue to try and find the issue and post an update when I have one….

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.