8000 ImportError: cannot import name 'smartplug' · Issue #87 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

ImportError: cannot import name 'smartplug' #87

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

Closed
akshayacharya97 opened this issue Jul 10, 2020 · 5 comments · Fixed by #90
Closed

ImportError: cannot import name 'smartplug' #87

akshayacharya97 opened this issue Jul 10, 2020 · 5 comments · Fixed by #90

Comments

@akshayacharya97
Copy link
akshayacharya97 commented Jul 10, 2020

ImportError: cannot import name 'smartplug'
why does this error occur?
any solutions please

@rytilahti
Copy link
Member

You need to show what you are trying to do, the proper way to import would be from kasa import SmartPlug and use SmartPlug("123.123.123.123"), or import kasa and use kasa.SmartPlug().

@akshayacharya97
Copy link
Author

oops..i cloned the repo and tried executing this program:

import asyncio
from kasa import SmartPlug
from pprint import pformat as pf

async def main():
plug = SmartPlug("192.xxx.x.xx")
asyncio.run(plug.update())
await plug.turn_on()

asyncio.run(main())

and error : Traceback (most recent call last):
File "kasa.py", line 4, in
from kasa import SmartPlug
File "/home/k 8000 asa/kasa.py", line 4, in
from kasa import SmartPlug
ImportError: cannot import name 'SmartPlug'

@rytilahti
Copy link
Member

rename the python file from kasa.py to something else and it should work. Currently it is trying to import SmartPlug from the file itself.

@akshayacharya97
Copy link
Author
akshayacharya97 commented Jul 15, 2020

oops thanks a lot.. @rytilahti
i did accordingly and when i run this, i am getting this new error.

import asyncio
from kasa import SmartPlug
from pprint import pformat as pf


async def main():
    print("entering")
    plug = SmartPlug("192.xxx.x.xx")
    asyncio.run(plug.update())
    await plug.turn_on()

asyncio.run(main())
Traceback (most recent call last):
  File "uvlight.py", line 14, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
    return future.result()
  File "uvlight.py", line 10, in main
    asyncio.run(plug.update())
  File "/usr/lib/python3.8/asyncio/runners.py", line 33, in run
    raise RuntimeError(
RuntimeError: asyncio.run() cannot be called from a running event loop
sys:1: RuntimeWarning: coroutine 'SmartDevice.update' was never awaited

@rytilahti
Copy link
Member

You cannot use asyncio.run() inside an already running event loop (inside async def main() you started in the last line), use await plug.update() instead.

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

Successfully merging a pull request may close this issue.

2 participants
0