来自mandrill的ValidationError与google app engine的urlfetch

时间:2013-04-28 05:44:11

标签: python google-app-engine urlfetch mandrill

来自localhost的python 27的Google应用引擎应用尝试通过mandrill的服务发送邮件。

我收到了:

{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}

来自谷歌应用引擎中的此代码:

my_payload = 
{
 "key": mandrill_key,
 "message": {
      "html": "<p>Example HTML content</p>",
      "subject": "prueba redquintal",
      "from_email": "MY_EMAIL@XXX.com",
      "to": [
        {
        "email": "SOME_EMAIL@gmail.com",
        }
        ]
    }
}

try:
    content = urlfetch.fetch(mandrill_url, method=urlfetch.POST, headers={'Content-Type': 'application/json'}, payload=my_payload)
    if content.status_code == 200:

        # some_code

    else:

        # some_code


except urlfetch.DownloadError:

    # some_code

关于什么可能是问题的任何想法?

1 个答案:

答案 0 :(得分:2)

我认为有效载荷应该是一个字符串

,例如

import json
content = urlfetch.fetch(mandrill_url, method=urlfetch.POST, headers={'Content-Type': 'application/json'}, payload=json.dumps(my_payload))