使用 Pushbullet Ephemerals 时出现 400(错误请求)错误

400 (Bad Request) error when using Pushbullet Ephemerals

我正在开发一个简单的命令行 Pushbullet Python 项目,并且有以下代码:

from settings import *
import urllib
import urllib2


def pushSms(number, message):
    url = 'https://api.pushbullet.com/v2/ephemerals'
    values = {
        "type": "push",
        "push": {
            "type": "messaging_extension_reply",
            "package_name": "com.pushbullet.android",
            "source_user_iden": settings["PUSHBULLET_USER_IDEN"],
            "target_device_iden": settings["PUSHBULLET_SMS_IDEN"],
            "conversation_iden": number,
            "message": message
        }
    }

    headers = {"Authorization" : "Bearer " + settings["PUSHBULLET_API_KEY"]}

    data = urllib.urlencode(values)
    req = urllib2.Request(url, data, headers)
    response = urllib2.urlopen(req)
    return response

示例用法可能是 pushSms("555 555 5555", "Hi there!")

这利用了 Pushbullet android 应用程序对 SMS 的访问,如记录here. I've checked my settings variables and they're all valid (in fact, they're currently in use in a JavaScript version of nearly this exact code in another project of mine

我怀疑这是一个基本的 Python syntax/urllib2 误用或错误,但我已经 staring/Googling 几个小时了,看不到我的错误。想法?

我不能确定(服务器的响应可能包含更多信息),但因为我们接受表单编码和 json 请求,您可能需要设置 header "Content-Type: application/json" 根据要求。

如果不是这样,您可以 post 400 响应的 body 吗?