1

As is similar on another post about this problem I receive the error,

"message": "Please enter your API key, or email and password.", 
"errors": [] 

when trying the script,

#API key stored as an enviroment variable
PLANET_API_KEY = os.getenv('api key here')

item_type = "REOrthoTile"

#API request object
search_request = {
    "interval": "day",
    "item_types": [item_type],
    "filter": combined_filter
}

#first post request
search_result = \
    requests.post(
        'https://api.planet.com/data/v1/quick-search',
        auth=HTTPBasicAuth(PLANET_API_KEY, ''),
        json=search_request)

however I do not get the error when using the script,

#API key stored as an enviroment variable
PLANET_API_KEY = os.getenv('api key here')

item_type = "REOrthoTile"

#API request object
search_request = {
    "interval": "day",
    "item_types": [item_type],
    "filter": combined_filter
}

#first post request
search_result = \
    requests.post(
        'https://api.planet.com/data/v1/stats',
        auth=HTTPBasicAuth(PLANET_API_KEY, ''),
        json=search_request)

another post (planet quick-search api not recognizing authentication?) had this same error and this (https://gis.stackexchange.com/a/239588/139012) response mentioned that a flag may be misconfigured, I cannot find a way to change this though.

To clarify, the API is accepted with the stats search result but not with the quick-search.

I removed my personal api key for security reasons but can send it for tests if needed

  • Please provide a link to the other post. – PolyGeo Mar 19 at 22:09
  • Could you log into Planet Explorer to confirm that your account has been set up properly and that you are able to view and download data there? If that works, then I'll need to get your user email or API key in order to investigate further. – bosth Mar 21 at 11:43
  • Hi @bosth, I can download fine through Planet Explorer, I have currently made a work around using the client filter and the 'PL_API_KEY' variable. Its not pretty but it gives me the results I need. 'os.environ['PL_API_KEY']='f4168dd427ed4a179c30189adfbc749e' PLANET_API_KEY = os.getenv('PL_API_KEY') ##PLANET_API_KEY = api.ClientV1() client = api.ClientV1(api_key="f4168dd427ed4a179c30189adfbc749e")' I apologize for the formatting of this comment. – Benjam Mar 21 at 20:50
  • Glad you got it working. We will reset your API key now to prevent someone else from using it. Check your account page for the new key. – bosth Mar 21 at 21:04
  • Thank you :)... – Benjam Mar 21 at 21:05
0

The line PLANET_API_KEY = os.getenv('api key here') is the problem here. There are two ways to get this to work.

First, if you are using an environment variable to store your API key so that it does not need to be hardcoded in each script or program, then you would need to make just a small change. For example, if you are storing the key in the variable API_KEY, then your code would look like this:

PLANET_API_KEY = os.getenv('API_KEY')

However, if you do want to use your API key directly in the code, the line would be:

PLANET_API_KEY = 'f4168dd427ed4a179c30189adfbc749e` # THIS IS NOT A REAL API KEY!

The first approach is better if you are going to have lots of scripts or will need to change API key at times. But you will need to set an environment variable, which is done differently depending on which operating system you are using.

  • Thank you, that makes much more sense. At the time I was just trying anything to bypass the problem I was having just to get everything working. Really appreciate the input. – Benjam Mar 21 at 22:32
  • You're welcome. Please mark as the solution if possible! – bosth Mar 21 at 22:39
  • To add to this, now that my imagery is downloading from my GeoJSON file upload, the downloads are not a complete scene. I cant seem to find a coverage filter or any documentation on how to deal with this, is there anything you know of that could help? I can start a new thread with my entire thread if necessary. – Benjam Mar 21 at 23:14
  • Best to create a new question with the details! – bosth Mar 22 at 2:06

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.