フィッシング URL の可能性を検証するための小さな機能を実装しようとしていますが、Google Safe Browsing API を使用するのが良い出発点になると考えました。
API ドキュメントを読んだ後、私は物事を処理できると思い、次のコードをまとめました。
import requests
import json
url = "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=<REDACTED>"
headers = {'content-type': 'application/json'}
payload = {'client': {'clientId': "mycompany", 'clientVersion': "0.1"},
'threatInfo': {'threatTypes': ["SOCIAL_ENGINEERING", "MALWARE"],
'platformTypes': ["ANY_PLATFORM"],
'threatEntryTypes': ["URL"],
'threatEntries:': [{'url': "http://www.urltocheck1.org"}]}}
print (json.dumps(payload, indent=4))
r = requests.post(url, headers=headers, json=payload)
私がする場合
print (json.dumps(payload, indent=4)
それはすべて大丈夫に見えます。しかし、Google から返された返信は同意しません。
{'エラー': {'メッセージ': '無効な JSON ペイロードを受信しました。\'threat_info\' の不明な名前 "threat_entries:": フィールドが見つかりません。 /google.rpc.BadRequest', 'fieldViolations': [{'field': 'threat_info', 'description': '無効な JSON ペイロードを受け取りました。不明な名前 "threat_entries:" at \'threat_info\': フィールドが見つかりません.'}]}]}} {'X-Frame-Options': 'SAMEORIGIN', 'Transfer-Encoding': 'chunked', 'Cache- Control': 'private', 'Date': 'Tue, 25 Oct 2016 07:55:30 GMT', 'Content-Type': 'application/json; charset=UTF-8', 'Alt-Svc': 'quic=":443"; ma=2592000; v="36,35,34,33,32"', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'X-XSS-Protection': '1; mode=block', 'Server': 'ESF'} application/json; 文字セット=UTF-8
いつものように、自分の間違いを見つけることができません。他の誰かがそれを見つけて、私を正しい軌道に乗せることはできますか?