python - google qpx with python3. HTTP Error 400: Bad Request -


not sure i'm doing incorrectly here. i'm running python 3.5 on macbook pro. given dictionary:

 data = {'request': {'passengers': {'adultcount': 2,    'childcount': 0,    'infantinlapcount': 0,    'infantinseatcount': 0,    'seniorcount': 0},   'refundable': 'false',   'slice': [{'date': '2016-01-01',     'destination': 'pmi',     'maxstops': '0',     'origin': 'zrh'},    {'date': '2016-01-10',     'destination': 'zrh',     'maxstops': 0,     'origin': 'pmi'}],   'solutions': 50}} 

so should quoted quoted.

now do:

url = "https://www.googleapis.com/qpxexpress/v1/trips/search?key={api_key}".format(api_key = ios_key) 

where ios_key ios key got api console. i'm not sure whether have selected right kind of key.

after this, run:

import urllib urllib.request import urlopen, request binary_data = urllib.parse.urlencode(data).encode('utf-8') myreq = request(url, binary_data, {'content-type': 'application/json'}) urlopen(myreq) 

my stacktrace is:

httperror                                 traceback (most recent call last) <ipython-input-167-aa1da44f3dff> in <module>() ----> 1 urlopen(myreq)  /users/eron/anaconda/lib/python3.5/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)     160     else:     161         opener = _opener --> 162     return opener.open(url, data, timeout)     163      164 def install_opener(opener):  /users/eron/anaconda/lib/python3.5/urllib/request.py in open(self, fullurl, data, timeout)     469         processor in self.process_response.get(protocol, []):     470             meth = getattr(processor, meth_name) --> 471             response = meth(req, response)     472      473         return response  /users/eron/anaconda/lib/python3.5/urllib/request.py in http_response(self, request, response)     579         if not (200 <= code < 300):     580             response = self.parent.error( --> 581                 'http', request, response, code, msg, hdrs)     582      583         return response  /users/eron/anaconda/lib/python3.5/urllib/request.py in error(self, proto, *args)     507         if http_err:     508             args = (dict, 'default', 'http_error_default') + orig_args --> 509             return self._call_chain(*args)     510      511 # xxx want abstract factory knows when makes  /users/eron/anaconda/lib/python3.5/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)     441         handler in handlers:     442             func = getattr(handler, meth_name) --> 443             result = func(*args)     444             if result not none:     445                 return result  /users/eron/anaconda/lib/python3.5/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)     587 class httpdefaulterrorhandler(basehandler):     588     def http_error_default(self, req, fp, code, msg, hdrs): --> 589         raise httperror(req.full_url, code, msg, hdrs, fp)     590      591 class httpredirecthandler(basehandler):  httperror: http error 400: bad request 

anybody faced similar issue?


Comments