Fix failing serpapi response processing for Google Maps API (#14817)

**Description:** Fix for processing for serpapi response for Google Maps
API
**Issue:** Due to the fact corresponding
[api](https://serpapi.com/google-maps-api) returns 'local_results' as
list, and old version requested `res["local_results"].keys()` of the
list. As the result we got exception: ```AttributeError: 'list' object
has no attribute 'keys'```.

Way to reproduce wrong behaviour:
```
    params = {
        "engine": "google_maps",
        "type": "search",
        "google_domain": "google.de",
        "ll": "@51.1917,10.525,14z",
        "hl": "de",
        "gl": "de",
    }
    search = SerpAPIWrapper(params=params)
    results = search.run("cafe")
```

---------

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
Co-authored-by: Ran <rccalman@gmail.com>
pull/15438/head
Evgenii Molov 9 months ago committed by GitHub
parent da0f750a0b
commit b4ec340fb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -211,9 +211,14 @@ class SerpAPIWrapper(BaseModel):
if "buying_guide" in res.keys():
snippets.append(res["buying_guide"])
if "local_results" in res.keys() and "places" in res["local_results"].keys():
if "local_results" in res and isinstance(res["local_results"], list):
snippets += res["local_results"]
if (
"local_results" in res.keys()
and isinstance(res["local_results"], dict)
and "places" in res["local_results"].keys()
):
snippets.append(res["local_results"]["places"])
if len(snippets) > 0:
return str(snippets)
else:

Loading…
Cancel
Save