400在python下使用pushalot api时的错误请求

2024-05-13 20:44:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码,我试图用Pushalot Apias Pushalot向Windows Phone发送消息,但没有任何示例。你知道吗

我知道我的api密钥工作正常,因为cURL方法工作正常,但是我修改过的python脚本不工作,继续得到--400,错误的请求,我不知道为什么。你知道吗

有什么想法吗?你知道吗

#!/usr/bin/python

from urllib import urlencode
from httplib import HTTPSConnection, HTTPException
from ssl import SSLError


pushalot_authorizationtoken = 'xxxxxxxxxxxxxxx'
pushalot_title = 'title'
pushalot_body = 'body'

http_handler = HTTPSConnection("pushalot.com")

data = {'AuthorizationToken': pushalot_authorizationtoken,
        'Title': pushalot_title.encode('utf-8'),
        'Body': pushalot_body.encode('utf-8') }

try:
    http_handler.request("POST",
                            "/api/sendmessage",
                            headers = {'Content-type': "application/x-www-form-urlencoded"},
                            body = urlencode(data))
except (SSLError, HTTPException):
    print("Pushalot notification failed.")            

response = http_handler.getresponse()

print(response.status, response.reason)

Tags: fromimportapihttptitleresponsebodyhandler