python - Django 没有收到电报 webhook
问题描述
我正在尝试构建一个电报机器人。我正在使用 django 应用程序。我托管了我的 django 应用程序,它运行良好。我正在使用 https 的 pythonanywhere 服务器上运行。我成功设置了我的网络钩子,它工作得很好。但我不知道为什么我的 django 服务器没有收到任何响应。这是我的views.py 代码
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import requests
@csrf_exempt
def telegram_bot(request):
# print(request.GET)
# print(request.POST)
print("this is sample")
if request.method == 'POST':
requests.get('https://api.telegram.org/bot<token>/sendMessage?chat_id=<id>&text=this is a sample text')
return HttpResponse(status=200)
我只是在我的日志中打印一些示例消息,并将示例消息发送回电报到相应的聊天 ID。但是这段代码没有被触发,我不确定为什么会这样。
最后,我尝试了这个 https://api.telegram.org/bot /getWebhookInfo
它显示我在 pending_update_count 中尚未发送大约 22 条消息。
任何帮助都是可以接受的,谢谢
解决方案
推荐阅读
- c# - 如何为从方法返回的 IEnumerable 设置 MaxLengthAttribute(用于生成 swagger maxItems 属性)
- python-3.x - 按特定字符拆分所有列名,并将最后一部分作为 Pandas 中的新列名
- swiper - 如何制作这样的刷机?
- python - 回滚多行 SQL 事务的潜在问题
- python - TypeError:“地图”对象不可下标 - Python
- css - 如何更改闪亮仪表板布局中的 tabPanel 宽度?
- python - 将 json 对象插入数据湖
- python - 如何将参数仅传递给 PySpark ML Pipeline 对象的一部分?
- android - 如何设置 CompanionDeviceManager.associate() 的超时时间?
- python - Transformer 库缓存路径没有改变