我正在尝试Amadeus python-sdk。当我致电航班提供价格api时:
amadeus.post('/v1/shopping/flight-offers/pricing', body)
我收到以下答复:
{
"errors":[
{
"code":"38189",
"title":"Internal error",
"detail":"An internal error occurred, please contact your administrator",
"status":"500"
}
]
}
这是我用过的尸体:
body = {'data': {'type': 'flight-offers-pricing', 'flightOffers': [{'type': 'flight-offer', 'id': '1', 'source': 'GDS', 'instantTicketingRequired': False, 'nonHomogeneous': False, 'oneWay': False, 'lastTicketingDate': '2020-03-01', 'numberOfBookableSeats': 4, 'itineraries': [{'duration': 'PT14H10M', 'segments': [{'departure': {'iataCode': 'GIG', 'at': '2020-03-01T23:30:00'}, 'arrival': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-02T12:10:00'}, 'carrierCode': 'AT', 'number': '212', 'aircraft': {'code': '788'}, 'operating': {'carrierCode': 'AT'}, 'id': '3', 'numberOfStops': 0, 'blacklistedInEU': False}, {'departure': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-02T15:45:00'}, 'arrival': {'iataCode': 'MAD', 'terminal': '4S', 'at': '2020-03-02T17:40:00'}, 'carrierCode': 'AT', 'number': '970', 'aircraft': {'code': '73G'}, 'operating': {'carrierCode': 'AT'}, 'id': '4', 'numberOfStops': 0, 'blacklistedInEU': False}]}, {'duration': 'PT31H20M', 'segments': [{'departure': {'iataCode': 'MAD', 'terminal': '4S', 'at': '2020-03-05T18:40:00'}, 'arrival': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-05T20:30:00'}, 'carrierCode': 'AT', 'number': '971', 'aircraft': {'code': '738'}, 'operating': {'carrierCode': 'AT'}, 'id': '47', 'numberOfStops': 0, 'blacklistedInEU': False}, {'departure': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-06T16:40:00'}, 'arrival': {'iataCode': 'GIG', 'at': '2020-03-06T22:00:00'}, 'carrierCode': 'AT', 'number': '213', 'aircraft': {'code': '788'}, 'operating': {'carrierCode': 'AT'}, 'id': '48', 'numberOfStops': 0, 'blacklistedInEU': False}]}], 'price': {'currency': 'USD', 'total': '2778.98', 'base': '2568.00', 'fees': [{'amount': '0.00', 'type': 'SUPPLIER'}, {'amount': '0.00', 'type': 'TICKETING'}]}, 'pricingOptions': {'fareType': ['PUBLISHED'], 'includedCheckedBagsOnly': True}, 'validatingAirlineCodes': ['AT'], 'travelerPricings': [{'travelerId': '1', 'fareOption': 'STANDARD', 'travelerType': 'ADULT', 'price': {'currency': 'USD', 'total': '1625.49', 'base': '1520.00'}, 'fareDetailsBySegment': [{'segmentId': '3', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRA', 'class': 'D', 'includedCheckedBags': {'quantity': 3}}, {'segmentId': '4', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRA', 'class': 'D', 'includedCheckedBags': {'quantity': 3}}, {'segmentId': '47', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRA', 'class': 'X', 'includedCheckedBags': {'quantity': 2}}, {'segmentId': '48', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRA', 'class': 'X', 'includedCheckedBags': {'quantity': 2}}]}, {'travelerId': '2', 'fareOption': 'STANDARD', 'travelerType': 'CHILD', 'price': {'currency': 'USD', 'total': '1153.49', 'base': '1048.00'}, 'fareDetailsBySegment': [{'segmentId': '3', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRACH', 'class': 'D'}, {'segmentId': '4', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRACH', 'class': 'D'}, {'segmentId': '47', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRACH', 'class': 'X'}, {'segmentId': '48', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRACH', 'class': 'X'}]}]}]}}
我与邮递员测试了相同的请求,它奏效了。知道是什么原因造成的吗?
谢谢。
答案 0 :(得分:0)
我能够解决此问题。 首先,我检查了请求的标题和正文:
amadeus.post('/v1/shopping/flight-offers/pricing', data)
使用此代码
try:
pricing = amadeus.post('/v1/shopping/flight-offers/pricing', body)
print(pricing.result)
except ResponseError as error:
print('headers: ', error.response.request.headers)
print('body: ', error.response.request.params)
这些是我得到的标题:
{
'User-Agent': 'amadeus-python/3.1.0 python/3.6.8',
'Accept': 'application/json, application/vnd.amadeus+json',
'Authorization': 'Bearer ...'
}
根据他们的postman collection,需要Content-Type标头。 我克隆了repo并将Content-Type标头添加到发布请求中,并且工作正常。
答案 1 :(得分:0)
SDK已更新,可以解决此问题。您可以安装新版本(3.2.0)。