Error on executing the example
ramonck opened this issue · comments
Ramon Lima commented
Hi,
Ubuntu 20.04
Python 3.8.2
Installation:
pip3 install git+https://git@github.com/p4kl0nc4t/kyros
pip3 install pyqrcode
I tried your example and I got the following error:
Traceback (most recent call last):
File "wa.py", line 40, 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 616, in run_until_complete
return future.result()
File "wa.py", line 14, in main
whatsapp = await kyros.Client.create()
NameError: name 'kyros' is not defined
Running as:
python3 wa.py
The example code:
import asyncio
import logging
import pyqrcode
from kyros import Client, WebsocketMessage
logging.basicConfig()
# set a logging level: just to know if something (bad?) happens
logging.getLogger("kyros").setLevel(logging.WARNING)
async def main():
# create the Client instance using create class method
whatsapp = await kyros.Client.create()
# do a QR login
qr_data, scanned = await whatsapp.qr_login()
# generate qr code image
qr_code = pyqrcode.create(qr_data)
print(qr_code.terminal(quiet_zone=1))
try:
# wait for the QR code to be scanned
await scanned
except asyncio.TimeoutError:
# timed out (left unscanned), do a shutdown
await whatsapp.shutdown()
return
# how to send a websocket message
message = kyros.WebsocketMessage(None, ["query", "exist", "1234@c.us"])
await whatsapp.websocket.send_message(message)
# receive a websocket message
print(await whatsapp.websocket.messages.get(message.tag))
if __name__ == "__main__":
asyncio.run(main())
Faiz Jazadi commented
I don't seem to be able to reproduce the issue. Will be closing this issue.
Ramon Lima commented
Hi @p4kl0nc4t I just tried again and I got this error now in Jupyter.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-2-4ff2bc354e6b> in <module>
38
39 if __name__ == "__main__":
---> 40 asyncio.run(main())
/usr/lib/python3.8/asyncio/runners.py in run(main, debug)
31 """
32 if events._get_running_loop() is not None:
---> 33 raise RuntimeError(
34 "asyncio.run() cannot be called from a running event loop")
35
RuntimeError: asyncio.run() cannot be called from a running event loop
Ramon Lima commented
Now I got it working in notebook
Now I'm going to start playing with it a little bit.
import asyncio
import logging
import pyqrcode
from kyros import Client, WebsocketMessage
logging.basicConfig()
# set a logging level: just to know if something (bad?) happens
logging.getLogger("kyros").setLevel(logging.WARNING)
async def main():
# create the Client instance using create class method
whatsapp = await Client.create()
# do a QR login
qr_data, scanned = await whatsapp.qr_login()
# generate qr code image
qr_code = pyqrcode.create(qr_data)
#print(qr_code.terminal(quiet_zone=1))
try:
# wait for the QR code to be scanned
await scanned
except asyncio.TimeoutError:
# timed out (left unscanned), do a shutdown
await whatsapp.shutdown()
return
# how to send a websocket message
#message = kyros.WebsocketMessage(None, ["query", "exist", "1234@c.us"])
#await whatsapp.websocket.send_message(message)
# receive a websocket message
print(await whatsapp.websocket.messages.get(message.tag))
#if __name__ == "__main__":
# asyncio.run(main())
await main()