Веб-хуки не отправляются в Python при использовании формата JSON вместо Discord.PY - PullRequest
0 голосов
/ 15 января 2020

Я пытаюсь, чтобы webhook отправлял этот код, но по какой-то причине он не отправляет. Прошел через отладчик на VS C и не могу найти причину. Код с участием веб-хаков ниже

(Да, я импортировал js, discord.py и запросы. Заголовки в порядке, и все должно работать, однако всякий раз, когда я использую JSON Format вместо discord.py - json лучше и быстрее, чем discord.py - никогда не отправляет)

def savetofile():
        sess=requests.session()
        while True:
                if reqthreadcount==0:
                        print("Exiting saving thread {0}".format(threading.currentThread()._ident))
                        return
                try:
                        f=savequeue.get(timeout=5)
                except:
                        continue
                if f in CURRENTPIDS:
                        continue
                try:
                        gh=sess.get("https://imgur.com/a/{0:06d}".format(f))
                        print("Saving PID: {0}".format(f))
                        lh=open(str(f)+".jpeg",'wb')
                        lh.write(gh.content)
                        lh.close()
                        headers: {
                        "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36",
                        "content-type": "application/json"
                        }
                        webhook_url = "insertyourwebhook"
                        slack_data = {
                            "embed": {
                                "title": "insert title",
                                "thumbnail": {
                                    "url": "https://imgur.com/a/owrNtki"
                                },
                                "image": {
                                    "url": 'https://imgur.com/a/{0}'.format(f)"
                                },
                                "footer": {
                                    "text": "Author123"
                                }
                            }
                        }
                        response = requests.post(webhook_url, json=slack_data, headers=headers)
                        if response.status_code!= 200:
                                'Request to webhook returned an error %s, the response is \n%s'
                                (response.status_code, reponse.text)

                except:
                        mn=open("FAILED.txt",'a')
                        mn.write(str(f)+"\n")
                        mn.close()
...