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

async await issue depending on script environment #643

Open
vladikoff opened this issue Oct 12, 2024 · 0 comments
Open

async await issue depending on script environment #643

vladikoff opened this issue Oct 12, 2024 · 0 comments

Comments

@vladikoff
Copy link

vladikoff commented Oct 12, 2024

2024-10-11 22:03:31.301 DEBUG (MainThread) [custom_components.pyscript.eval] file.lights-room.lights_room: calling __aexit__(<aiohttp.client.ClientSession object at 0x7f511cca10>, <class 'TypeError'>, object dict can't be used in 'await' expression, <traceback object at 0x7f3ed66600>, {})

I have matching aiohttp versions, running Python 3.12.4 inside a venv on a Mac:

@service
async def lights_room():
  async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=ssl_context)) as session:

        try:
            async with session.get(
                f"{uri}/endpoint",
                headers={...}
            ) as response:
                response.raise_for_status()

                data = await response.json()
                #            ^ this await is required when running the script on a Mac. However pyscript throws an error here.

The pyscript environment requires me to remove the await in the response.json() line, otherwise I get an error mentioned above. Running the script on my laptop requires the awaot. I read somewhere that the awaits are "optional", but doesn't seem so.
I run the script on the laptop via asyncio.run(lights_room()), which I guess is not the same way pyscript does it?

anyway the current workaround is to adjust the script for the pyscript env and remove the awaits.

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

No branches or pull requests

1 participant