如何使用Python请求通过HTTP基本身份验证连接到HTTPS API?

2024-10-01 19:25:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过Python请求使用Guesty API,它要求通过HTTPS发出请求并通过httpbasicauth进行身份验证(如下说明)。在

我尝试过使用Python请求和HTTPBasicAuth,如下所示,但是得到了响应[404]。在

如何使用Python请求连接到guestyapi?在

To use the Guesty API, you’ll need a private API key that is linked to your account. You can generate one here

Be sure to keep this API key private. All API requests must be made over HTTPS and are authenticated via HTTP Basic Auth. Use your API key as the username and secret as the password.

import requests
from requests.auth import HTTPBasicAuth

print requests.get("https://superhostuser.herokuapp.com/api/v2/", auth=HTTPBasicAuth(api, secret))

文件还规定:

The default base URL for Guesty API is: https://superhostuser.herokuapp.com/api/v2/

Note: for security reasons, all Guesty APIs are served over HTTPS only.


Tags: andthetokeyhttpsapiyouris

热门问题