-
|
I am not super familiar with asyncio. I am building a program to build custom views on the monarch data. However, I am running into an issue whenever with the asyncio part: mm = MonarchMoney() SyntaxError: 'await' outside async function When run individually, they work fine. But when trying to run them all at once, it triggers an error. Is there a way around this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
@francijb , can you share a bit more of the code? I have a feeling you are calling the As an example, this will cause the error you are seeing: def my_func() {
...
mm = MonarchMoney()
await mm.login(user_name, pw) # This fails because an async keyword is being used inside a non-async function
}If that's what's happening, you have two options:
For the first option, this is what your refactored code would look like from monarchmoney import MonarchMoney
async def my_func() {
mm = MonarchMoney()
await mm.login(user_name, pw) # everything is async now, so it works!
}For the latter, you can do the following: import asyncio
from monarchmoney import MonarchMoney
def my_func() {
mm = MonarchMoney()
asyncio.get_event_loop().run_until_complete(mm.login(user_name, pw)) # 'converts' the async function in to a synchronous one
} |
Beta Was this translation helpful? Give feedback.
@francijb , can you share a bit more of the code? I have a feeling you are calling the
awaitinside of a non-async function, but would be good to see the code around it to confirm.As an example, this will cause the error you are seeing:
If that's what's happening, you have two options:
async def my_func()awaitas wellawaituse the asyncio library functions to wrap i…