这是我的看法:
@csrf_exempt
def send_notification(request):
message = {"name": "xxxxx","email": "xxxxxx@gmail.com"}
registration_ids = ['xxxxxxxxxxxxxx']
post_data = {"data":message,"registration_ids":registration_ids}
headers = {'Content-Type': 'application/json', 'Authorization':'key=xxxxxx'}
import requests
post_response = requests.post(url='https://android.googleapis.com/gcm/send', data=simplejson.dumps(post_data), headers=headers)
print post_response
print simplejson.dumps([post_response.headers, post_response.text])
to_json = {'status':str(post_response)}
return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')
服务器日志:
[error] <Response [401]>
输出:
TypeError at /send_notification/
CaseInsensitiveDict(
{
"alternate-protocol": "443:quic",
"x-xss-protection": "1; mode=block",
"x-content-type-options": "nosniff",
"transfer-encoding": "chunked",
"expires": "Fri, 08 Nov 2013 10:29:45 GMT",
"server": "GSE",
"cache-control": "private, max-age=0",
"date": "Fri, 08 Nov 2013 10:29:45 GMT",
"x-frame-options": "SAMEORIGIN",
"content-type": "text/html; charset=UTF-8"
}) is not JSON serializable
我正在使用requests
它给了我上面的行。
我还尝试测试其他一些有效的网址!
可能出了什么问题?