텔레그램 봇 만들기 파트에서 에러가 발생합니다.
1142
작성한 질문수 3
안녕하세요, 강사님.
강의 잘 듣고 있습니다:)
현재 크롤링 후 텔레그램을 통해 메세지를 보내고, 장고에 연결하는 부분을 학습하고 있습니다.
강의 영상에서는 별도의 동기/비동기 처리 없이 진행이 가능했는데
그대로 따라하였더니 coroutine 'bot.sendMessage' was never awaited 에러가 발생하여
강의에서 작성한 for문을 async def test(): 로 함수로 감싼 뒤 스크립트 하단에
asyncio.run(test()) 함수를 실행시키니 에러가 발생하지 않고 텔레그램으로 메세지가 보내지더라구요.
그런데, 해당 스크립트를 django에 연결하기 위해선 def run 함수를 통해 진행해야하는데,
함수 형태가 조금 변경돼서 그런지 위와 같이 async, asyncio, await 등을 사용해봐도
에러가 발생하여 진행이 되지 않고있습니다..
어떻게 하면 좋을까요?? 코드 및 에러 첨부드립니다.
from asyncore import loop
from datetime import time
from bs4 import BeautifulSoup
import requests
import telegram
import asyncio
from hotdeal.models import Deal
async def test():
response = requests.get('https://www.ppomppu.co.kr/zboard/zboard.php?id=ppomppu')
soup = BeautifulSoup(response.text, "html.parser")
BOT_TOKEN = 'TOKEN'
bot = telegram.Bot(token=BOT_TOKEN)
for item in soup.find_all("tr", {'class': ["list1", "list0"]}):
try:
image = item.find("img", class_="thumb_border").get("src")[2:]
title = item.find("font", class_="list_title").text.strip()
link = item.find("font", class_="list_title").parent.get("href")
link = "https://www.ppomppu.co.kr/zboard/" + link
reply_count = int(item.find("span", class_="list_comment2").text)
up_count = item.find_all("td")[-2].text
up_count = up_count.split("-")[0].strip()
up_count = int(up_count)
if up_count >= 5:
if Deal.objects.filter(link__iexact=link).count() == 0:
Deal(image_url = image, title = title, link = link,
reply_count = reply_count, up_count = up_count).save()
await bot.sendMessage(-1001897599228, '{} {}'.format(title, link))
except Exception as e:
print(e)
def run():
asyncio.run(test())에러 메세지입니다.
invalid literal for int() with base 10: ''
'NoneType' object has no attribute 'text'
invalid literal for int() with base 10: ''
'NoneType' object has no attribute 'text'
invalid literal for int() with base 10: ''
'NoneType' object has no attribute 'text'
invalid literal for int() with base 10: ''
You cannot call this from an async context - use a thread or sync_to_async.
'NoneType' object has no attribute 'text'
invalid literal for int() with base 10: ''
'NoneType' object has no attribute 'text'
You cannot call this from an async context - use a thread or sync_to_async.
'NoneType' object has no attribute 'text'
You cannot call this from an async context - use a thread or sync_to_async.
You cannot call this from an async context - use a thread or sync_to_async.
You cannot call this from an async context - use a thread or sync_to_async.
You cannot call this from an async context - use a thread or sync_to_async.
You cannot call this from an async context - use a thread or sync_to_async.
You cannot call this from an async context - use a thread or sync_to_async.
'NoneType' object has no attribute 'text'
'NoneType' object has no attribute 'text'
invalid literal for int() with base 10: ''
'NoneType' object has no attribute 'text'
invalid literal for int() with base 10: ''
답변 0
11. 데이터를 목록화하는 리스트와 튜플 에서 콘솔 실행시
0
10
1
ZIP 파일
0
19
2
26강 13F 강의 불일치 및 질문 요청
0
22
3
[업로드오류] 강의 내용과 제목 불일치
0
20
2
강의와는 별개로...
0
26
3
[예제002] 에서 파인썬 인터프리터가 없습니다
0
28
3
65강 소리
0
15
1
텔레그램 봇 명령어 오류 질문드립니다.
0
13904
4
pip install djangoframework 하면 버전이 안맞다는데 왜그럴가요
1
361
1
런서버해도 안되는데 왜그럴까요
0
301
1
리스폰 결과가 왜 2줄만 나올까요??
0
498
4
urls.py 에서 import 문제
0
309
0
aws 서버 중지됨
0
302
1
hotdeal부분이 추가되지 않아요
0
203
1
from os import times 1, 2 번 줄에 있는 것들은 자동적으로 불러와지는것 같은데 정상인거죠?
0
246
1
혹시 ^C% 이건 어떻게 하나요?
0
309
4
flutter를 이용하여 모바일 앱 만들기
0
269
1
2강/hotdeal의 views.py 부분 에러입니다.
0
212
1
AWS 사용 중단 관련 문의
0
282
3
AttributeError: 'NoneType' object has no attribute 'text'오류가 뜹니다.
0
9508
1
from hotdeal.models import Deal
0
276
2
No (valid) module for script 'crawler' found
0
382
3
runscript 질문드립니다.
0
438
3
pip3 install syntax error
0
294
1





