QPX Express API from Python

纵饮孤独 提交于 2019-12-09 03:09:27

Here is a solution using the excelent requests library.

import json
import requests

api_key = "YOUR API KEY HERE"
url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=" + api_key
headers = {'content-type': 'application/json'}

params = {
  "request": {
    "slice": [
      {
        "origin": "TXL",
        "destination": "LIM",
        "date": "2015-01-19"
      }
    ],
    "passengers": {
      "adultCount": 1
    },
    "solutions": 2,
    "refundable": False
  }
}

response = requests.post(url, data=json.dumps(params), headers=headers)
data = response.json()
print data

I am not sure why you request is not working. Maybe it is really the request parameters that were wrong. The date definitely needs to be in the future!

False needs to be in lowercase in JSON, so you need to quote it in Python, like this "refundable" : "false". Otherwise, your query looks good (obviously you'll need to update the date). By the way, it isn't good practice to include your API key in a public forum.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!