2013-04-28 34 views
1

Google應用程序引擎應用程序與本地主機上的python 27試圖通過mandrill的服務發送郵件。從這個代碼在谷歌應用程序引擎來自mandrill的ValidationError與谷歌應用程序引擎的urlfetch

{"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": "[email protected]", 
     "to": [ 
     { 
     "email": "[email protected]", 
     } 
     ] 
    } 
} 

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 

上什麼可能是問題的任何想法?

回答

2

我認爲有效載荷應該是一個字符串

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

優秀@Xavier,謝謝 – Ott0 2013-04-28 15:36:43