I can successfully reproduce the first two API calls from this walkthrough: https://www.planet.com/docs/api-quickstart-examples/step-1-search/ (as I have an API key). However, the third call (the POST to 'https://api.planet.com/data/v1/quick-search') gives me:
{
"message": "Please enter your API key, or email and password.",
"errors": []
}
I have copied and pasted everything from this example.
Is this expected because I am a free user?
EDIT - Responding to Richard Law - Yes, I have a mac and echo $PLANET_API_KEY
shows me my key. As would be expected given the fact that the first two calls worked..
EDIT #2 - Responding to Bosth - I can show you my code, but it really is not that interesting because it's the exact same code as the example. Here it is. I'm running the two requests in one script to make sure it's the same environment..
import os
import requests
from requests.auth import HTTPBasicAuth
geo_json_geometry = {
"type": "Polygon",
"coordinates": [
[
[
-122.52227783203125,
40.660847697284815
],
[
-122.52227783203125,
40.987154933797335
],
[
-122.01690673828124,
40.987154933797335
],
[
-122.01690673828124,
40.660847697284815
],
[
-122.52227783203125,
40.660847697284815
]
]
]
}
# filter for items the overlap with our chosen geometry
geometry_filter = {
"type": "GeometryFilter",
"field_name": "geometry",
"config": geo_json_geometry
}
# filter images acquired in a certain date range
date_range_filter = {
"type": "DateRangeFilter",
"field_name": "acquired",
"config": {
"gte": "2016-07-01T00:00:00.000Z",
"lte": "2016-08-01T00:00:00.000Z"
}
}
# filter any images which are more than 50% clouds
cloud_cover_filter = {
"type": "RangeFilter",
"field_name": "cloud_cover",
"config": {
"lte": 0.5
}
}
# create a filter that combines our geo and date filters
# could also use an "OrFilter"
redding_reservoir = {
"type": "AndFilter",
"config": [geometry_filter, date_range_filter, cloud_cover_filter]
}
stats_endpoint_request = {
"interval": "day",
"item_types": ["REOrthoTile"],
"filter": redding_reservoir
}
# fire off the POST request
result = \
requests.post(
'https://api.planet.com/data/v1/stats',
auth=HTTPBasicAuth(os.environ['PLANET_API_KEY'], ''),
json=stats_endpoint_request)
print result.text
print
# Search API request object
search_endpoint_request = {
"item_types": ["REOrthoTile"],
"filter": redding_reservoir
}
result = \
requests.post(
'https://api.planet.com/data/v1/quick-search',
auth=HTTPBasicAuth(os.environ['PLANET_API_KEY'], ''),
json=search_endpoint_request)
print result.text
Answer
This is not expected. All accounts with Planet have the same access to the full metadata catalog; the only difference in restrictions is on downloading actual data.
According to the question the following code worked fine:
result = \
requests.post(
'https://api.planet.com/data/v1/stats',
auth=HTTPBasicAuth(os.environ['PLANET_API_KEY'], ''),
json=stats_endpoint_request)
print result.text
But this did not:
result = \
requests.post(
'https://api.planet.com/data/v1/quick-search',
auth=HTTPBasicAuth(os.environ['PLANET_API_KEY'], ''),
json=search_endpoint_request)
print result.text
This does suggest that PLANET_API_KEY
is not available in the second instance that you are running the code.
It would help clarify if the working and non-working code was posted as part of the question.
UPDATE I was able to reproduce the issue with the code provided and your API key. Further investigation showed that a flag in your account was misconfigured; I have just fixed it and API calls will now work.
No comments:
Post a Comment