Search code examples
pythonapipython-requestsazure-api-managementazure-api-apps

python - how to access an API from azurewebsites


I am trying to access an API which is at azurewebsites.net. I am new to Azure platform and I don't know if for accessing this API through my code, would I need any additional configurations in the Azure platform? I tried the normal request method to get the API data in python but it throws an authentication error. Do I need to register my app in the Azure?

Here's what I am trying:

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

Could someone please guide me through this? Thankyou.


Solution

  • Because I don't know what settings your azure website has done, so I can only give you a general solution.

    Steps to try:

    1. First of all, make sure that you can access your api site normally. You can test other interfaces to ensure that the api site is running normally.

    2. When the website is running normally, check whether the aad setting is made on the portal.

      enter image description here

    3. If not, please use postman to test the interface to ensure that it can be accessed normally in postman, and then use the code to test by checking the url, header and other parameters.

    4. 😋If yes, please obtain Beartoken and add it when accessing the interface. I see that you are using email and pass, then you can use ropc flow get Beartoken. Then you can bring this verification when you visit each interface.

      enter image description here

    Related post:

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