threatMatches.find() takes an object, not a (json) string?

166 views
Skip to first unread message

Peter Smith

unread,
Dec 21, 2017, 4:15:50 AM12/21/17
to Google Safe Browsing API
i'm trying to figure out if i should have known, from the docs or otherwise, that the threatMatches.find() method takes an object, presumably a dict, instead of a string (which is an object).

https://developers.google.com/safe-browsing/v4/reference/rest/v4/threatMatches/find

is this a python thing? that is, in a docstring declaration, if an argument is declared as type 'object', is it always a dict? or can it be anything, including a string?

could, or should, the find() method docstring specify a type more specific than 'object'? or is 'object' more than nothing in that it at least implies that the argument should maybe not be 'just' a string?

the find() method was accepting my string but then gave me a weird error:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://safebrowsing.googleapis.com/v4/threatMatches:find?alt=json&key=XXXXXXX returned "Invalid JSON payload received. Unknown name "": Root element must be a message.">

the argument i was passing in was a (json) string, but apparently it needed to be a dict (that presumably represents a json string somehow?).

thanks.

Peter Smith

unread,
Dec 21, 2017, 4:19:15 AM12/21/17
to Google Safe Browsing API

Ben Sanders

unread,
Dec 21, 2017, 1:23:01 PM12/21/17
to Google Safe Browsing API
Sorry for the confusion. Yes, it appears that it takes a python dict and converts it into json. The example in the pydoc is a valid python object (in this case, a dictionary with nested dictionaries/lists). That seems to be the method taken with the python APIs for non-primitive types. For Java, it automatically generates classes with getters and setters for specific fields: https://developers.google.com/resources/api-libraries/documentation/safebrowsing/v4/java/latest/index.html.

That API client is automatically generated based on our documentation and protobuf definitions. Since our API is more complicated than others, this mapping doesn't look very appealing. If it were hand written, it might do things like take the clientversion/clientid at the start and insert that into requests as needed. Or at least break the large object into several independent method inputs to be combined within the library.

Overall I would say that the auto-generated client is not very useful for this API. You essentially have the full URL you need to post to already, so the only question is if this library creates the json, or if you do. The update api requires more semantics regarding local DB setup, caching, etc that the auto-generated client doesn't help with either.

alid...@yahoo.com

unread,
Dec 24, 2017, 6:54:49 AM12/24/17
to Google Safe Browsing API
Reply all
Reply to author
Forward
0 new messages