google distance matrix with python -
my problem want distance around 4000 lat longs . have used google direction matrix service this. extend worked fine me. after getting error of invalid request .its because of method. want solution how can use distance matrix service post using python. appreciate on this. in advance.
i writing google distance matrix python using appengine, got struck urllib post method
code: url = 'http://maps.googleapis.com/maps/api/distancematrix/json'
conn = getconnection() cursor = conn.cursor() origins=[] try: cursor.execute('select username,lat,lng,cabno,orderno tripsheet order username;') origins= cursor.fetchall() except: self.response.out.write("some thing bad happened") conn.close() responsearray= [] o in origins : origin= {} key= "blah" origin = {"name":o[0],"key":key, "latitude":o[1],"longitude":o[2],"cabno":o[3],"order":o[4]} responsearray.append(origin) url=url+o[1]+','+o[2]+'|' values = { 'sensor' : 'false', 'mode' : 'driving', 'avoid' : 'tolls', 'destinations': '%s,%s' % (destination["lat"] ,destination["lon"]) } data = urllib.urlencode(values) req = urllib2.request(url, data) response = urllib2.urlopen(req) the_page = response.read() self.response.out.write(the_page)
i trying passing around 4000 origin , single destination.
getting below error message because taking . wanted convert post using urllib2:
traceback (most recent call last): file "/home/xxx/projects/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 714, in __call__ handler.get(*groups) file "/home/xxx/4.2workspace/routeoptimization/src/main.py", line 41, in self.calculate_indv_distance(destination) file "/home/xxx/4.2workspace/routeoptimization/src/main.py", line 109, in calculate_indv_distance response = urllib2.urlopen(req) file "/usr/lib/python2.7/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) file "/usr/lib/python2.7/urllib2.py", line 400, in open response = self._open(req, data) file "/usr/lib/python2.7/urllib2.py", line 418, in _open '_open', req) file "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain result = func(*args) file "/usr/lib/python2.7/urllib2.py", line 1207, in http_open return self.do_open(httplib.httpconnection, req) file "/usr/lib/python2.7/urllib2.py", line 1182, in do_open r = h.getresponse() file "/home/xxx/projects/google_appengine/google/appengine/dist/httplib.py", line 222, in getresponse deadline=self.timeout) file "/home/xxx/projects/google_appengine/google/appengine/api/urlfetch.py", line 266, in fetch return rpc.get_result() file "/home/xxx/projects/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 604, in get_result return self.__get_result_hook(self) file "/home/xxx/projects/google_appengine/google/appengine/api/urlfetch.py", line 370, in _get_fetch_result 'invalid request url: ' + url + error_detail) invalidurlerror: invalid request url: http://maps.googleapis.com/maps/api/distancematrix/
any appreciate.
Comments
Post a Comment