-
Notifications
You must be signed in to change notification settings - Fork 49
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
object str can't be used in 'await' expression in PyScript Async Functions #673
Comments
Please include your code. Try removing the awaits in your pyscript code. |
import aiohttp Base URLsAUTH_URL = "https://auth.quandify.com/" Replace with your actual credentialsACCOUNT_ID = # Your account ID Time range (example: Unix timestamps)FROM_TIMESTAMP = 1700000000 async def authenticate(account_id, password):
@service
async def get_aggregated_data(id_token, organization_id, from_ts, to_ts):
@service
Gives error log: Logger: custom_components.pyscript.file.Quandify.authenticate_quandify Error during authentication: object dict can't be used in 'await' expression |
import aiohttp Base URL for authenticationAUTH_URL = "https://auth.quandify.com/" Replace with your actual credentialsACCOUNT_ID = # Your account ID @service
This error originated from a custom integration. Logger: custom_components.pyscript.file.Quandify.authenticate_quandify_debug Exception during authentication: object str can't be used in 'await' expression |
Simple code to reproduce: def aio_test():
async with aiohttp.ClientSession() as session:
async with session.get("https://google.com") as response:
if response.status == 200:
return await response.text() Removing |
The issue is in async def ast_await(self, arg):
"""Evaluate await expr."""
coro = await self.aeval(arg.value)
if coro:
return await coro
return None In my local setup, I fixed it like this, and everything works perfectly: async def ast_await(self, arg):
"""Evaluate await expr."""
return await self.aeval(arg.value) @craigbarratt, can async def ast_await(self, arg):
"""Evaluate await expr."""
val = await self.aeval(arg.value)
if asyncio.iscoroutinefunction(val):
return await val
else:
return val No PR since I’m unsure which is correct. |
#643 the same |
I am encountering a persistent error in PyScript when trying to perform an asynchronous HTTP request using aiohttp. Despite adhering to the asyncio guidelines and leveraging Home Assistant’s async_get_clientsession, the following error occurs consistently. This error arises regardless of the specific HTTP client method (response.text(), response.json(), or others), suggesting a deeper issue with how PyScript interprets awaitable objects.
1. The same code works flawlessly in a standalone Python environment.
2. Using task.executor to offload synchronous requests calls also fails due to PyScript restrictions.
3. The issue persists across various attempts to simplify the logic.
The issue seems to stem from PyScript misinterpreting certain objects (e.g., str or dict) as awaitable. This is not typical behavior for asyncio or aiohttp and may indicate a PyScript-specific bug.
The text was updated successfully, but these errors were encountered: