0

Here is my simplified pyscript -

async def auth(brand):
    async with aiohttp.ClientSession() as session:
        async with session.post(url_auth) as resp:
            ...
            return auth_token_b64

@service
def get_counters(address_id):
    auth_token_b64 = await auth(brand)

    ...

It worked well when I used it locally with asyncio.run(get_counters(address_id=1)).

But now I've uploaded the file to Home Assistant and there I get the following error -

return auth_token_b64

TypeError: object str can't be used in 'await' expression

What is wrong here?

LA_
  • 19,823
  • 58
  • 172
  • 308
  • The syntax for async operations has changed. Please review the Pyscript website: [link](https://docs.pyscript.net/latest/guides/asyncio.html) – dancassin Aug 22 '23 at 16:19

1 Answers1

1

It looks like you're missing the async keyword before your get_counters function definition. This is causing the await expression inside get_counters to throw an error because it is not in an asynchronous context. To fix the issue, simply add the async keyword before your get_counters function definition:

@service
async def get_counters(address_id):
    auth_token_b64 = await auth(brand)

Can you try this?

Grimlock
  • 1,033
  • 1
  • 9
  • 23