3
$\begingroup$

When trying to import data from an https request I get the following error message.

request = HTTPRequest[ 
  <|"Scheme" -> "https", "Method" -> "GET", "Domain" -> "api.nasa.gov"
  , "Path" -> "planetary/earth/imagery"
  , "Query" -> {
      "lon" -> 100.75, "lat" -> 1.5, "cloud_score" -> True
    , "date" -> DateString[{2014, 02, 04}, "ISODate"]
    ,  "api_key" -> "DEMO_KEY"
    }
  |>
]
HTTPRequest[
  URL: https://api.nasa.gov/planetary/earth/imagery?... =2014-02-04&cloud_score=true&api_key=DEMO_KEY 
  ContentType: None
]

Generates HTTPRequest. The hyperlink works fine when clicking on it.

When trying to Import (or use URLRead) to bring the data

Import[request]

{"error" -> {"message" -> "Requests must be made over HTTPS. Try accessing the API at: \ https://api.nasa.gov/planetary/earth/imagery/?lon=100.75&lat=1.5&date=\ 2014-02-04&cloud_score=true&api_key=DEMO_KEY", "code" -> "HTTPS_REQUIRED"}}

$\endgroup$
  • 2
    $\begingroup$ I think it has something to do with the output being as HTTPRequest. If you use the following, it seems to work fine: Import["https://api.nasa.gov/planetary/earth/imagery/?lon=100.75&lat=1.5&date=2014-02-04&cloud_score=true&api_key=DEMO_KEY"] (At least it returns the same data as when I click the link) $\endgroup$ – kickert Oct 9 '18 at 2:40
3
$\begingroup$

To make a long story short: you need ...imagery/?... not ...imagery?... in your url.

When you click the hyperlink you will be redirected to the correct one, that is why you see an expected result. The 301 redirect response takes you there.

In principle MMA can handle redirects 301/302 and I don't know enough to judge this behavior so I'd ask WRI support how to classify this issue.

Meanwhile add /:

Import@HTTPRequest[<|"Scheme" -> "https", "Method" -> "GET", 
   "Domain" -> "api.nasa.gov", "Path" -> "planetary/earth/imagery/",(*!!*) 
   "Query" -> {"lon" -> 100.75, "lat" -> 1.5, 
     "date" -> DateString[{2014, 02, 04}, "ISODate"], 
     "cloud_score" -> True, "api_key" -> "DEMO_KEY"}|>]
{"date" -> "2014-02-04T03:30:01", "cloud_score" -> 0.0392665, 
 "resource" -> {"dataset" -> "LC8_L1T_TOA", "planet" -> "earth"}, 
 "service_version" -> "v1", 
 "id" -> "LC8_L1T_TOA/LC81270592014035LGN00", 
 "url" -> "https://earthengine.googleapis.com/api/thumb?thumbid=\
0d15ad8d2af6d8d0a6b083672514fae7&token=\
86cd0d3233be25e65e5f055ce5d2ed3c"}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.