tyson-swetnam / porder

Simple CLI for Planet ordersV2 API
https://tyson-swetnam.github.io/porder/
Apache License 2.0
48 stars 12 forks source link

"page" variable from api request has no "links" key #9

Closed rbavery closed 5 years ago

rbavery commented 5 years ago

I'm using the most recent version of porder in a python 2 environment and get the following when making an order

(porder-env) (v2-cloud)~/cloud-free-planet/notebooks$ porder idlist --input "/home/rave/cloud-free-planet/notebooks/test_tile_half.geojson" --start "2018-07-01" --end "2018-07-31" --item "PSScene4Band" --asset "analytic_sr" --number 10000 --outfile "/home/rave/cloud-free-planet/notebooks/test_half_ids.csv" --cmin 0 --cmax 1 --overlap 50
'features'
Traceback (most recent call last):
  File "/home/rave/anaconda3/envs/porder-env/bin/porder", line 11, in <module>
    load_entry_point('porder==0.1.7', 'console_scripts', 'porder')()
  File "/home/rave/anaconda3/envs/porder-env/lib/python2.7/site-packages/porder/porder.py", line 213, in main
    args.func(args)
  File "/home/rave/anaconda3/envs/porder-env/lib/python2.7/site-packages/porder/porder.py", line 71, in idlist_from_parser
    outfile=args.outfile)
  File "/home/rave/anaconda3/envs/porder-env/lib/python2.7/site-packages/porder/geojson2id.py", line 180, in idl
    while page['_links'].get('_next') is not None:
KeyError: '_links'

I've confirmed with porder quota that my credentials are initialized properly. Not sure what the issue is here but I can try to debug further and update.

samapriya commented 5 years ago

Could you share the geojson file for me to run tests?

rbavery commented 5 years ago

Sure here it is (github doesn't allow geojson file upload)

{
"type": "FeatureCollection",
"name": "test_tile_half",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -0.831053947078279, 5.733240915104465 ], [ -0.798653947078279, 5.733240915104465 ], [ -0.7986, 5.71 ], [ -0.831, 5.71 ], [ -0.831053947078279, 5.733240915104465 ] ] ] } }
]
}

I've figured out some of what is happening, on the first iteration of the paging while loop in geojson2id.py..

    while page['_links'].get('_next') is not None:
        page_url = page['_links'].get('_next')
        page = SESSION.get(page_url).json()
        ids = handle_page(page,asset,num,outfile,gmain,ovp)

page does have a _links key with results selection_536

But in the next iteration of the while loop

selection_537

It looks like my credentials are forgotten/dropped from memory? Then the while loop fails here because now page has no _links, only errors and messages

samapriya commented 5 years ago

I am able to run the tools for your AOI on both windows and a Linux machine, am not really sure what is going on there. I could not replicate your error. For the query, you made within that one month period and with an overlap of 50, there are 8 assets.

20180726_095804_103d
20180712_103425_0f21
20180709_103420_100d
20180710_095700_0e0f
20180711_103459_0f2a
20180707_095733_103e
20180703_095732_1015
20180702_095725_101f
rbavery commented 5 years ago

I found the problem, my PL_API_KEY was exported as a shell variable and was set to my old key. I think the script might have been picking up my new key from planet init and then the old key from my shell environment, thanks for checking.