V
V
Volzas2020-07-12 16:28:33
Python
Volzas, 2020-07-12 16:28:33

Python error got Future attached to a different loop, how to solve?

I am making a telegram bot on Telebot, there is a function with which I create a qiwi account for payment, an async function, then when the user clicks on the buy button I call this function, but I get an error. The function itself is
kassa = QiwiKassa('Secret_key')
async def test_kassa():

async with QiwiKassa("Secret_key") as kassa:
kassa.tools.return_type = returns.ReturnType.JSON
sent_invoice = await kassa.new_bill(1.01, lifetime= 44)
print("Url to pay:", sent_invoice['payUrl'])
await kassa.close()
code where I call the function -
elif call.data == 'qiwi':
loop = asyncio.new_event_loop()
asyncio.set_event_loop (loop
)
#then another code is executed,
but as soon as it reaches the function execution, I get an error -
Traceback (most recent call last):
File "C:/Users/Elena/PycharmProjects/SSDBot/setup.py", line 246, in
bot.polling (none_stop=True)
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\__init__.py", line 392, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\__init__.py", line 416, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C: \Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 109,in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\ six.py", line 703, in reraise
raise value
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 60, in run
task (*args, **kwargs)
File "C:/Users/Elena/PycharmProjects/SSDBot/setup.py", line 170, in pay_check
loop.run_until_complete(test_kassa())
File "C:\Users\Elena\AppData\ Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 583, in run_until_complete
return future.result()
File "C:/Users/Elena/PycharmProjects/SSDBot/setup.py", line 44, in test_kassa
sent_invoice = await kassa.new_bill(1.01, lifetime=44)
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\aioqiwi\kassa\requests.py", line 119, in new_bill
response = await self.connector.request("PUT", url, data=data)
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\site-packages\aioqiwi\core\ connectors\asyncio.py", line 194, in request
loop=self.loop,
File "C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\asyncio\tasks.py", line 435, in wait_for
await waiter
RuntimeError: Task cb=[_run_until_complete_cb() at C:\Users\Elena\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py:157]> got Future attached to a different loop
Please help, I have already tried a lot of ways, but I still can not perform this function. I use aioqiwi to create invoices.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question