i got invalid request response from google maps api in python when I copy the link to chrome it works fine
Question: What can be the reson?

    
    
    {
       "html_attributions" : [],
       "results" : [],
       "status" : "INVALID_REQUEST"
    }
    

in Chrome fine:

    
    
    {
    "html_attributions": [],
    "next_page_token": "CqQDkgEAAFOOGlx1ov_HPteOZTqmNHkYFmUDfDDmlQn0XpcBzeYWgCNmexMAOS1KRvaStWwFRvLDDKEUsGyFwguXrBHTuvdfmu4REV4VPH-ALqsxb7cl9wrRLhUQTyjnMilf68qgafL2Eb7GZ3OXH2s4vpsC2HRaclVPbp53kz1NZY7NeKDNPzUOW-tIHpw_X3U_2NhfUbDu-1gMFOOaMCOoaQt7FHW51ktIm4UFrn6OfytS_VdIp7RgOMp1HISIbx8GW2l1MKnUZaPEztlwJi3OvK9n4waWOvS7uUd_PPy1xPYJWv-yKtG3Ehok-LOjCv-jkB_Ki4uqjWCGW4kD5L_aKp2gjECT-ny-1aTpjtJc8a9p1Fhx_Wdbf2vee5hCZfbaSxseRgsHd0POFPaIFwIZYg6GJHHkbjW6gfbnI67oI9nC3dTH86gWzyFCsG_n0hyhCg-oHzO3mxlaDDxCM6xv1Nbp5AY4u03NGIpzTNoRekJ-EtA1d7cYu-yZ2XFzHXJGkxyWHobe_UdwLa6b4ZUQD8qCoKGQ429MxeY6x5R05AYg4Q1BEhA7UkpwystS_CoYKCCJXeoZGhRToQEqwA-RwiEMbAqwfN3n89aVZg",
    "results": [...],
    "status": "OK"
    }
    

The code:

    
    
    # -*- coding: utf-8 -*-
    import urllib
    import json
    import csv
    import hashlib
    import time
    
    
    YOUR_API_KEY = "SECRET"
    
    
    def geocode(addr):
        url = ("http://maps.googleapis.com/maps/api/"
               "geocode/json?address=%s&sensor=false") % (urllib.quote(addr))
        data = urllib.urlopen(url).read()
        info = json.loads(data).get("results")[0].get("geometry").get("location")
        return info
    
    
    def geocode2(r):
        info = []
    
        url_base = ("https://maps.googleapis.com/maps/api/place/search/json?"
                    "location=%s,%s&radius=500&types=food&sensor=false&"
                    "key=%s&pagetoken=%s") % (
                    r['lat'],
                    r['lng'],
                    YOUR_API_KEY,
                    ''
                    )
    
        data = urllib.urlopen(url_base).read()
        info.extend(json.loads(data).get("results"))
        token = json.loads(data).get("next_page_token")
    
        while token:
            time.sleep(5)
            new_url = url_base + token
            data = urllib.urlopen(new_url).read()
            token = json.loads(data).get("next_page_token")
            info.extend(json.loads(data).get("results"))
    
        print len(info)
    
        l = []
        for i in info:
            t = (i["name"],
                i["vicinity"],
                i["geometry"]["location"]["lat"],
                i["geometry"]["location"]["lng"]
                )
    
            l.append(t)
        return l
    
    
    for place in geocode2(geocode('Polska, Warszawa, Pl. Zawiszy 1')):
        print place
    

The output: <https://gist.github.com/andilab/078ea76b1f4d70704b50>


Answer: I guess it is much about time. I added time.sleep(5) in while loop where I try
fetching new google places with next_page_token() and it works.

The quota from docs confirms my guess.

> The maximum number of results that can be returned is 60. **There is a short
> delay between when a next_page_token is issued, and when it will become
> valid.**

From: [Google Places API
Doc](https://developers.google.com/places/documentation/search)

Worth mention, that anyway maximum number of places returned will be **60**!

