python - 如何从 azurewebsites 访问 API

python - how to access an API from azurewebsites

我正在尝试访问位于 azurewebsites.net 的 API。我是 Azure 平台的新手,我不知道如果要通过我的代码访问此 API,我是否需要在 Azure 平台中进行任何其他配置?我尝试了正常的请求方法来获取 python 中的 API 数据,但它抛出了身份验证错误。我需要在 Azure 中注册我的应用程序吗?

这是我正在尝试的:

r = requests.get("url",
             headers={
                 "Accept": "application/json"},
             cookies={},
             auth=('email', 'pass'),
             )

有人可以指导我完成这个吗?谢谢。

因为不知道你的azure网站做了什么设置,所以只能给你一个大概的解决方案

尝试步骤:

  1. 首先,请确保您可以正常访问您的api站点。可以测试其他接口,保证api站点正常运行

  2. 当网站运行正常时,检查portal是否设置了aad

  3. 如果不行,请使用postman测试接口,确保在postman中可以正常访问,然后通过检查使用代码测试url、header 和其他参数。

  4. 如果是,请获取Beartoken并在访问界面时添加。我看到你用的是email和pass,那你可以用ropc flow获取Beartoken。然后在访问各个界面的时候带上这个验证即可。

相关post:

Is there a way to improve the performance of MSAL-browser js login?