首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我使用Scrapy在管道中发送通知时,电报响应400

当我使用Scrapy在管道中发送通知时,电报响应400
EN

Stack Overflow用户
提问于 2022-09-23 11:27:36
回答 1查看 40关注 0票数 1

我试着用电报机器人发送通知,但我得到了response 400

我的代码(正在编写中):

代码语言:javascript
复制
    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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-23 11:50:13

如果要发送包含htmlmarkdown标记作为响应的内容,则需要将其传递给解析器。

如果使用html,则添加parse_mode=html

如果您使用的是标记,请将parse_mode=markdown添加到URL

变化

代码语言:javascript
复制
tel_url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}"         

代码语言:javascript
复制
tel_url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}&parse_mode=html"

message需要与URL兼容

代码语言:javascript
复制
import urllib
urllib.parse.quote(message)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73827009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档