Skip to content

Instantly share code, notes, and snippets.

@wilhelmklopp
Created January 27, 2016 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilhelmklopp/942c4b4aa6e026dc18cf to your computer and use it in GitHub Desktop.
Save wilhelmklopp/942c4b4aa6e026dc18cf to your computer and use it in GitHub Desktop.
Skyscanner API ISO-3166-1 Alpha 3 code problem
# The following snippet DOES NOT work
import requests
import datetime
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
api_key = "YOUR-API-KEY-HERE"
url = "http://api.skyscanner.net/apiservices/pricing/v1.0/"
headers = {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"Accept": "application/json"
}
payload = {
"apiKey": api_key,
"country": "GER",
"currency": "EUR",
"locale": "en-US",
"originplace": "BRU",
"destinationplace": "MAD",
"outbounddate": str(tomorrow),
"adults": 1,
"locationschema": "Iata",
}
r = requests.post(url, headers=headers, data=payload)
print r.status_code
print r.text
print r.headers
# The following snippet DOES work
import requests
import datetime
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
api_key = "YOUR-API-KEY-HERE"
url = "http://api.skyscanner.net/apiservices/pricing/v1.0/"
headers = {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"Accept": "application/json"
}
payload = {
"apiKey": api_key,
"country": "DE",
"currency": "EUR",
"locale": "en-US",
"originplace": "BRU",
"destinationplace": "MAD",
"outbounddate": str(tomorrow),
"adults": 1,
"locationschema": "Iata",
}
r = requests.post(url, headers=headers, data=payload)
print r.status_code
print r.text
print r.headers
@wilhelmklopp
Copy link
Author

ISO-3166-1 alpha 3 codes are not accepted and the API will return 500 Internal Server Error.
ISO-3166-1 alpha 2 codes are accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment