how to ping a closed loop website from a databricks notebook

Srujan Mara 0 Reputation points
2024-09-03T18:18:01.6233333+00:00

I'm trying to connect to another 3rd party website using databricks notebook with an API call.
The website i'm trying to connect to is a configured to open in the allowed IP lists and whenever i'm trying to connect to the website i'm facing the below error.

Error : ConnectTimeout: HTTPSConnectionPool(host='app.

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,153 questions
{count} votes

Accepted answer
  1. Konstantinos Passadis 19,066 Reputation points MVP
    2024-09-03T19:25:51.5333333+00:00

    Hello @Srujan Mara

    Does the external resource logs the call ? is it rejected ?

    Please try to whitelist the correct IP of your Databricks Cluster

    Find the IP :

    import requests

    try:

    response = requests.get('https://api.ipify.org')

    response.raise_for_status() # Raise an exception for bad status codes

    public_ip = response.text

    print(f"Your outbound IP address is: {public_ip}")

    except requests.exceptions.RequestException as e:

    print(f"An error occurred: {e}")

    Also i suppose you have increased the timeout right ?

    --

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards


1 additional answer

Sort by: Most helpful
  1. Konstantinos Passadis 19,066 Reputation points MVP
    2024-09-03T18:27:08.6866667+00:00

    Hello @Srujan Mara

    Welcome to Microsoft QnA!

    Let me kindly ask

    have you validated the external API connectivity ? is it healthy if you try to connect from anywhere else ?

    If yes then

    • Check Logs
    • Increase timeout :

    import requests

    try:

    response = requests.get('https://app.<xyz>.sts.<abc>.com/api/v2/version/', timeout=10) # Adjust timeout as needed

    response.raise_for_status() # Raise an exception for bad status codes

    # Process the API response here

    data = response.json()

    print(data)

    except requests.exceptions.Timeout:

    print("The request timed out. Please try again later.")

    except requests.exceptions.RequestException as e:

    print(f"An error occurred: {e}")

    Validate Outbound Connectivity from your Databricks cluster

    Use this sample to check outbound access and DNS resolution:

    import requests

    try:

    response = requests.get("https://www.google.com", timeout=5)

    response.raise_for_status() # Raise an exception for bad status codes

    print("Connection successful!")

    except requests.exceptions.RequestException as e:

    print(f"Connection error: {e}")

    Kindly provide your feedback !

    --

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.