coroutine was never awaited, но все await проставлены. Что может быть не так?
import time
from telegram import Bot
import asyncio
chat_id = -****
bot = Bot("*****")
async def send_random_cat() -> None:
url = f'****=${time.time()}'
return await bot.send_photo(chat_id, url)
async def main() -> None:
return await send_random_cat()
print('Cat has been sent')
if __name__ == "__main__":
main()
Сначала выводит ошибку:
RuntimeWarning: coroutine 'send_random_cat()' was never awaited
send_random_cat()
ставлю await
Потом тоже самое, но с main. Тоже ставлю await, теперь он говорит
RuntimeWarning: coroutine 'main' was never awaited
main()
Но тут-то куда await
ставить?
На домашнем ноуте - всё работает без await
. А при загрузке на сервер - вот эта ошибка.
Подскажите, пожалуйста, в чём дело?
Измененный код
import time
from telegram import Bot
import asyncio
chat_id = -**** #замените на свое значение, подробнее ниже
bot = Bot("564****EE")
async def main():
await send_random_cat()
async def send_random_cat():
url = f'http***?t=$'
bot.send_photo(chat_id, url)
if __name__ == "__main__":
asyncio.run(main())
import time
from telegram import Bot
import asyncio
chat_id = -** #замените на свое значение, подробнее ниже
bot = Bot("**")
def main():
asyncio.run(send_random_cat())
async def send_random_cat():
url = f'**}'
await bot.send_photo(chat_id, url)
if __name__ == "__main__":
main()