我试着用电报机器人发送通知,但我得到了response 400。
我的代码(正在编写中):
def sendnotifications(self, token):
cursor = self.cnx.cursor()
req = requests
cursor.execute("SELECT * FROM notificate WHERE token= '"+token+"'")
notifications = cursor.fetchall()
for notification in notifications:
print(notification)
productid = notification[1]
url = notification[3]
name = notification[2]
old = notification[4]
new = notification[5]
price_difference = old - new
percentage = price_difference / old
percentage_str = str("%.2f" % (percentage * 100))
message = "<b>" + name + "</b>" + "\n\n" + \
str(old) + " TL >>>> " + \
str(new) + f" TL - <b>{percentage_str}%</b>" + "\n\n" + \
url + "\n\n" + \
"https://www.hepsiburada.com/" + "ara?q=" + productid + "\n\n"
TOKEN = "xxxxxxxxxxxxxxxxxxxxx"
chat_id = "xxxxxxxxxxxxx"
tel_url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}"
try:
r = requests.get(tel_url
)
print(r)
except RequestException:
return False
cursor.close()
return True我想我犯了错误,但我找不到任何解决办法。
谢谢你的帮助。
我得到了这样的回应:
(137,'hbv00000s3cb8','Asus双GeForce RTX 2060 EVO 6GB 192Bit GDDR6 (DX12) PCI-E 3.0 Ekran Kartı(双RTX 2060-6G-EVO)‘,'https://www.hepsiburada.com/asus-dual-geforce-rtx-2060-evo-6gb-192bit-gddr6-dx12-pci-e-3-0-ekran-karti-dual-rtx2060-6g-evo-p-HBV00000S3CB8',Decimal('69000.00'),’10269.00‘,datetime.datetime(2022,9,23,11,26,51),(“‘zoagxalqgm”) 2022-09-23 11:26:51 urllib3.连接池调试:启动新的HTTPS连接(1):api.telegram.org:443 2022-09-23 11:26:52 urllib3.连接池调试:https://api.telegram.org:443 "GET“)%3C/b%3E%0A%0A69000.00%20TL%20%3E%3E%3E%3E%2010269.00%20TL%20-%20%3Cb%3E85.12%25%3C/b%3E%0A%0Ahttps://www.hepsiburada.com/asus-dual-geforce-rtx-2060-evo-6gb-192bit-gddr6-dx12-pci-e-3-0-ekran-karti-dual-rtx2060-6g-evo-p-HBV00000S3CB8%0A%0Ahttps://www.hepsiburada.com/ara?q=hbv00000s3cb8%0A%0A HTTP/1.1“400 73
发布于 2022-09-23 11:50:13
如果要发送包含html或markdown标记作为响应的内容,则需要将其传递给解析器。
如果使用html,则添加parse_mode=html
如果您使用的是标记,请将parse_mode=markdown添加到URL
变化
tel_url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}" 至
tel_url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}&parse_mode=html"message需要与URL兼容
做
import urllib
urllib.parse.quote(message)https://stackoverflow.com/questions/73827009
复制相似问题