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

SyntaxError: 'async with' outside async function #23

Closed
ThyMollusk opened this issue May 28, 2021 · 3 comments
Closed

SyntaxError: 'async with' outside async function #23

ThyMollusk opened this issue May 28, 2021 · 3 comments

Comments

@ThyMollusk
Copy link

ThyMollusk commented May 28, 2021

How do I fix this?
My code:

from bscscan import BscScan

async with BscScan('MY_API') as bsc:
    print(await bsc.get_bnb_balance(address="0x0000000000000000000000000000000000001004"))

results in:

SyntaxError: 'async with' outside async function

@pcko1
Copy link
Owner

pcko1 commented May 29, 2021

try this

import asyncio
from bscscan import BscScan

async def main():
  async with BscScan('MY_API') as bsc:
    print(await bsc.get_bnb_balance(address="0x0000000000000000000000000000000000001004"))

if __name__=="__main__":
  asyncio.run(main())

I suggest either reading up a bit on asyncio or using the simple (sync) version of the client [1].

Thank you for this question though, I will improve the documentation by adding this example.

@pcko1 pcko1 closed this as completed May 29, 2021
@pt40039
Copy link

pt40039 commented May 30, 2021

hello, im fully new into this, can you explain to me how to run the code at all :) ? like, can i download any chrome extension to run the code and then enter my preferences in a UI ?

@pcko1
Copy link
Owner

pcko1 commented May 30, 2021

@pt40039 I'm afraid you have to look into basic python coding because, until then, this software is going to be of no use to you unfortunately.

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

3 participants