Google app engine 如何解决“问题”;接收到无效的JSON负载。“未知名称”;错误
我试图从Google安全浏览API v4获得正确的响应。尽管我收到错误“接收到无效的JSON有效负载。未知名称” 我使用了一个基于上提到的有效负载示例的有效负载 我的有效载荷有问题。我认为它应该是一个字符串,而不是一个真正的dict。当我使用dict时,我得到一个错误:TypeError:hastype,但应该是:str,unicode 我使用的代码是:Google app engine 如何解决“问题”;接收到无效的JSON负载。“未知名称”;错误,google-app-engine,safe-browsing-api,Google App Engine,Safe Browsing Api,我试图从Google安全浏览API v4获得正确的响应。尽管我收到错误“接收到无效的JSON有效负载。未知名称” 我使用了一个基于上提到的有效负载示例的有效负载 我的有效载荷有问题。我认为它应该是一个字符串,而不是一个真正的dict。当我使用dict时,我得到一个错误:TypeError:hastype,但应该是:str,unicode 我使用的代码是: result = urlfetch.fetch(url, method=urlfetch.POST, payload=payload) ur
result = urlfetch.fetch(url, method=urlfetch.POST, payload=payload)
url是(带[api密钥]的当然是我的api密钥):
有效负载是以下字符串(不是python dict):
作为输出,我希望得到一些JSON,这表明这个url是安全的。然而,我得到了以下结果:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"{\n \"client\": {\n \"clientId\": \"myproject\",\n \"clientVersion\": \"42\"\n },\n \"threatInfo\": {\n \"threatTypes\": [\"MALWARE\", \"SOCIAL_ENGINEERING\"],\n \"platformTypes\": [\"WINDOWS\"],\n \"threatEntryTypes\": [\"URL\"],\n \"threatEntries\": [\n {\"url\":\"http://www.example.com/\"}\n ]\n }\n }\": Cannot bind query parameter. Field '{\n \"client\": {\n \"clientId\": \"myproject\",\n \"clientVersion\": \"42\"\n },\n \"threatInfo\": {\n \"threatTypes\": [\"MALWARE\", \"SOCIAL_ENGINEERING\"],\n \"platformTypes\": [\"WINDOWS\"],\n \"threatEntryTypes\": [\"URL\"],\n \"threatEntries\": [\n {\"url\":\"http://www' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": [similar as the message above]
}
]
}
]
}
}
有什么想法吗,怎么了
谢谢,urlfetch应该包含标题内容类型:application/json
result = urlfetch.fetch(url, method=urlfetch.POST, payload=payload, headers={'Content-Type': 'application/json'})
尝试删除jsonHi Benjamin中的换行符,谢谢您的建议。然而,这没有帮助。
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"{\n \"client\": {\n \"clientId\": \"myproject\",\n \"clientVersion\": \"42\"\n },\n \"threatInfo\": {\n \"threatTypes\": [\"MALWARE\", \"SOCIAL_ENGINEERING\"],\n \"platformTypes\": [\"WINDOWS\"],\n \"threatEntryTypes\": [\"URL\"],\n \"threatEntries\": [\n {\"url\":\"http://www.example.com/\"}\n ]\n }\n }\": Cannot bind query parameter. Field '{\n \"client\": {\n \"clientId\": \"myproject\",\n \"clientVersion\": \"42\"\n },\n \"threatInfo\": {\n \"threatTypes\": [\"MALWARE\", \"SOCIAL_ENGINEERING\"],\n \"platformTypes\": [\"WINDOWS\"],\n \"threatEntryTypes\": [\"URL\"],\n \"threatEntries\": [\n {\"url\":\"http://www' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": [similar as the message above]
}
]
}
]
}
}
result = urlfetch.fetch(url, method=urlfetch.POST, payload=payload, headers={'Content-Type': 'application/json'})