Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in docs for running search against Data API doesn't work #1054

Closed
favyen2 opened this issue Sep 13, 2024 · 2 comments · Fixed by #1055
Closed

Example in docs for running search against Data API doesn't work #1054

favyen2 opened this issue Sep 13, 2024 · 2 comments · Fixed by #1055
Labels

Comments

@favyen2
Copy link

favyen2 commented Sep 13, 2024

Expected behavior
The example at https://planet-sdk-for-python-v2.readthedocs.io/en/stable/get-started/upgrading/#asynchronous-methods run successfully when API key is provided, producing a list of items from the API.

Actual behavior (describe the problem)
It runs into an error because client.search is closed outside of the with block. Here is the code snippet:

import asyncio
from datetime import datetime
from planet import Session
from planet import data_filter as filters

async def do_search():
    async with Session() as session:
        client = session.client('data')
        date_filter = filters.date_range_filter('acquired', gte=datetime.fromisoformat("2022-11-18"), lte=datetime.fromisoformat("2022-11-21"))
        cloud_filter = filters.range_filter('cloud_cover', lte=0.1)
        download_filter = filters.permission_filter()
    return [item async for item in client.search(["PSScene"], filters.and_filter([date_filter, cloud_filter, download_filter]))]

items = asyncio.run(do_search())

Here is the error:

RuntimeError: Cannot send a request, as the client has been closed.

Related Issues
none

Workaround
The example should be corrected:

import asyncio
from datetime import datetime
from planet import Session
from planet import data_filter as filters

async def do_search():
    async with Session() as session:
        client = session.client('data')
        date_filter = filters.date_range_filter('acquired', gte=datetime.fromisoformat("2022-11-18"), lte=datetime.fromisoformat("2022-11-21"))
        cloud_filter = filters.range_filter('cloud_cover', lte=0.1)
        download_filter = filters.permission_filter()
        return [item async for item in client.search(["PSScene"], filters.and_filter([date_filter, cloud_filter, download_filter]))]

items = asyncio.run(do_search())

Minimum, Complete, Viable Code Sample
It is an example from the docs so it is already minimal.

Environment Information

  • Operation System Information (python -c "import platform; print(platform.platform())")

Linux

  • Python version (python -c "import sys; print(sys.version.replace('\n', ' '))")

3.12.2

  • Planet package version (planet -v)
$ planet -v
Usage: planet [OPTIONS] COMMAND [ARGS]...
Try 'planet --help' for help.

Error: No such option: -v

Installation Method

pip

@favyen2 favyen2 added the bug label Sep 13, 2024
@favyen2
Copy link
Author

favyen2 commented Sep 13, 2024

@stephenhillier
Copy link
Contributor

stephenhillier commented Sep 13, 2024

Thanks @favyen2!

I opened #1055 to fix these two issues. I also note the issue template wants you to run planet -v which isn't a valid option- I'll follow up and see what we can do there (either fix the issue template or the option).

If you have any other issues or feedback, please let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants