标签: safe-browsing-api

如何修复“收到无效的 JSON 负载。未知名称”错误

我尝试从 Google Safe Browsing API v4 获得正确响应。虽然我收到错误“收到无效的 JSON 负载。未知名称”。

我使用了基于https://developers.google.com/safe-browsing/v4/lookup-api 中提到的负载示例的负载

我的有效载荷有问题。我认为它应该是一个字符串,而不是一个真正的字典。当我使用字典时,我收到错误: TypeError: has type ,但预期是: str, unicode 之一

我使用的代码是:

result = urlfetch.fetch(url, method=urlfetch.POST, payload=payload)
Run Code Online (Sandbox Code Playgroud)

网址是([api-key] 当然是我的 api-key):

https://safebrowsing.googleapis.com/v4/threatMatches:find?key=[api-key]
Run Code Online (Sandbox Code Playgroud)

有效负载是以下字符串(不是 python 字典):

{
  "client": { 
     "clientId": "myproject", 
     "clientVersion": "42" }, 
  "threatInfo": { 
     "threatTypes": ["MALWARE", "SOCIAL_ENGINEERING"], 
     "platformTypes": ["WINDOWS"], 
     "threatEntryTypes": ["URL"], 
     "threatEntries": [ {"url":"http://www.example.com/"} ] } 
}
Run Code Online (Sandbox Code Playgroud)

作为输出,我期望一些 JSON 表明这个 url 是安全的。但是我得到以下结果:

{ 
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"{\n    \"client\": {\n      \"clientId\":      \"myproject\",\n      \"clientVersion\": …
Run Code Online (Sandbox Code Playgroud)

google-app-engine safe-browsing-api

4
推荐指数
1
解决办法
1万
查看次数