如何向 Amadeus API 提出请求?出现网络错误

How to make requests to Amadeus API? Got Network Error

我刚刚注册了我的测试应用程序并获得了 Api 密钥和 Api 密钥。我正在尝试使用 Python SDK:

发送请求
from amadeus import Client, ResponseError

amadeus1 = Client(
client_id='my_API_key_here',
client_secret='my_secret_key_here'
)

response = amadeus1.reference_data.locations.airports.get(longitude=49.000, latitude=2.55)
print(response.data)

我收到网络错误。我究竟做错了什么?

编辑:

问题来自开发环境中的 SSL 证书问题。


我无法重现问题,API 似乎有效。您的示例 returns 是一个空数组,因为测试环境中的数据有限。为此 API 涵盖的国家/地区是:美国、西班牙、英国、德国和印度。

因此,如果您尝试使用伦敦的地理位置

response = amadeus1.reference_data.locations.airports.get(longitude=0.1278, latitude=51.5074)

如您所见,响应包含数据。

但我没有遇到网络问题。 如果问题仍然存在,请通过我们的门户联系我们的支持人员,分享您的用户名,以便我们检查您的 API 密钥和 API 机密。

几天前我又遇到了这个问题。我的问题是从本地环境发送请求。它试图验证 SSL 并导致了问题。

我通过包含一个供 urlopen 使用的 'unverified context' 来解决它。这不应在生产环境中使用。它可以从我的本地计算机向 Amadeus 测试和生产环境发出请求。

import ssl


def ssl_disabled_urlopen(endpoint):
    context = ssl._create_unverified_context()
    return urlopen(endpoint, context=context)


amadeus = Client(
    client_id = '<client_id>',
    client_secret = '<client_secret>',
    http=ssl_disabled_urlopen
)