cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Access Azure App service failed with 403 response

johnp
New Contributor II

We have an Azure app service written in Django.  From databricks notebook we sent curl command to test the connection between databricks and Azure AppService.  We got the following repsonse:

Error 403 - Forbidden

The web app you have attempted to reach has blocked your access.

How do I setup the the Django web service so Databrick notebook can access it?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz
Community Manager
Community Manager

Hi @johnp

Certainly! To set up your Django web service so that Databricks notebooks can access it, follow these steps:

  1. Sample Application:

  2. Create a Web App in Azure:

    • To host your application in Azure, create an Azure App Service web app:
      • You can use the Azure CLI, VS Code, Azure Tools extension pack, or the Azure portal.
      • Azure CLI commands:
        • Install the Azure CLI if you haven’t already.
        • Log in to Azure using az login.
        • Create the web app and other resources, then deploy your code to Azure using:
          az webapp up --runtime PYTHON:3.9 --sku B1 --logs
          
          (Replace --runtime with the appropriate Python version if needed.)
  3. Configure Access:

    • Ensure that your Django app allows access from Databricks by configuring CORS (Cross-Origin Resource Sharing) settings.
    • In your Django app’s settings, add the following middleware:
      MIDDLEWARE = [
          # ...
          'corsheaders.middleware.CorsMiddleware',
          # ...
      ]
      
    • Set the CORS_ALLOW_ALL_ORIGINS setting to True:
      CORS_ALLOW_ALL_ORIGINS = True
      
    • You can also specify specific origins if needed:
      CORS_ALLOWED_ORIGINS = [
          "https://your-databricks-url",
          # Add other allowed origins here
      ]
      
  4. Deploy to Azure:

    • Deploy your Django app to Azure using the same steps as mentioned earlier.
    • Once deployed, your Databricks Notebooks should be able to access your Azure App Service.

Remember to replace placeholders like your-databricks-url with the actual URLs relevant to your setup. If you encounter any issues, feel free to ask for further assistance! 🚀🌐

 

View solution in original post

1 REPLY 1

Kaniz
Community Manager
Community Manager

Hi @johnp

Certainly! To set up your Django web service so that Databricks notebooks can access it, follow these steps:

  1. Sample Application:

  2. Create a Web App in Azure:

    • To host your application in Azure, create an Azure App Service web app:
      • You can use the Azure CLI, VS Code, Azure Tools extension pack, or the Azure portal.
      • Azure CLI commands:
        • Install the Azure CLI if you haven’t already.
        • Log in to Azure using az login.
        • Create the web app and other resources, then deploy your code to Azure using:
          az webapp up --runtime PYTHON:3.9 --sku B1 --logs
          
          (Replace --runtime with the appropriate Python version if needed.)
  3. Configure Access:

    • Ensure that your Django app allows access from Databricks by configuring CORS (Cross-Origin Resource Sharing) settings.
    • In your Django app’s settings, add the following middleware:
      MIDDLEWARE = [
          # ...
          'corsheaders.middleware.CorsMiddleware',
          # ...
      ]
      
    • Set the CORS_ALLOW_ALL_ORIGINS setting to True:
      CORS_ALLOW_ALL_ORIGINS = True
      
    • You can also specify specific origins if needed:
      CORS_ALLOWED_ORIGINS = [
          "https://your-databricks-url",
          # Add other allowed origins here
      ]
      
  4. Deploy to Azure:

    • Deploy your Django app to Azure using the same steps as mentioned earlier.
    • Once deployed, your Databricks Notebooks should be able to access your Azure App Service.

Remember to replace placeholders like your-databricks-url with the actual URLs relevant to your setup. If you encounter any issues, feel free to ask for further assistance! 🚀🌐

 
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.