Skip to content Skip to sidebar Skip to footer

Google SafeBrowsing API: Always Getting An Error

I use google safe browsing API. So I tested this simple code: from safebrowsinglookup import SafebrowsinglookupClient class TestMe: def testMe(self): self.key='my_Vali

Solution 1:

The library doesn't support Python3.x.

In this case, you can either make it support Python3 (there is also an opened pull request for Python3 Compatibility), or make the request to "Google Safebrowsing API" manually.

Here's an example using requests:

import requests

key = 'your key here'
URL = "https://sb-ssl.google.com/safebrowsing/api/lookup?client=api&apikey={key}&appver=1.0&pver=3.0&url={url}"


def is_safe(key, url):
    response = requests.get(URL.format(key=key, url=url))
    return response.text != 'malware'


print(is_safe(key, 'http://addonrock.ru/Debugger.js/'))  # prints False
print(is_safe(key, 'http://google.com'))  # prints True

Just the same, but without third-party packages (using urllib.request):

from urllib.request import urlopen


key = 'your key here'
URL = "https://sb-ssl.google.com/safebrowsing/api/lookup?client=python&apikey={key}&appver=1.0&pver=3.0&url={url}"


def is_safe(key, url):
    response = urlopen(URL.format(key=key, url=url)).read().decode("utf8")
    return response != 'malware'


print(is_safe(key, 'http://addonrock.ru/Debugger.js/'))  # prints False
print(is_safe(key, 'http://google.com'))  # prints True

Post a Comment for "Google SafeBrowsing API: Always Getting An Error"