cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Databricks Free Trial Help
Engage in discussions about the Databricks Free Trial within the Databricks Community. Share insights, tips, and best practices for getting started, troubleshooting issues, and maximizing the value of your trial experience to explore Databricks' capabilities effectively.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

API access via python script

DanScho
Visitor

Hello,

I try to access an API via a python script.

I have access using postman. But if I try to access it via python in databricks, it will not work (timeout).

Here is my code:

import requests
import socket

headers = {
    'Content-Type': 'application/json',
    'x-api-key': '<api-key>',
    'User-Agent': 'PostmanRuntime/7.43.0',
    'Accept': '*/*',
    'Host': '<URL to host>',
    'Accept-Encoding': 'gzip, deflate, br',
    'Connection': 'keep-alive',
    'Content-Length': '105'
}
payload = {
    "result_l": "en",
    "result_n": 2,
    "texts": [
        "Text1.",
        "Text2"
    ]
}
 
    response = requests.post(url, headers=headers, json=payload, timeout=10)  # Timeout nach 10 Sekunden
    response.raise_for_status()  # Lรถst eine Ausnahme bei HTTP-Fehlern aus
    data = response.json()
    print(data)
 

Best regards,

Daniel

9 REPLIES 9

Walter_C
Databricks Employee
Databricks Employee

Are you running this from a notebook? if yes can you run bash command:

%sh

nc -vz prod-api.xsp.cloud.corpintra.net 443

I want to confirm your cluster is able to reach the endpoint.

yes, i use it from a notebook.

C:\Windows>nc -vz prod-api.xsp.cloud.corpintra.net 443
Der Befehl "nc" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

DanScho
Visitor

is "nc" a linux command? I use windows...

Walter_C
Databricks Employee
Databricks Employee

Sorry I am confused, you mentioned that you are running this in a notebook, this inside Databricks and running it through a cluster? if this is the case the command needs to be ran inside the notebook, you can add a new cell from it.


DanScho
Visitor

sorry for confusing... i missunderstood your question.... now I got it.

running this command in a notebook in databricks shows no result.... it is "loading" endlessly... I only can interrupt it....

DanScho
Visitor

now it shows:
nc: connect to prod-api.xsp.cloud.corpintra.net (53.13.186.164) port 443 (tcp) failed: Connection timed out

Walter_C
Databricks Employee
Databricks Employee

ok that means that your subnet for clusters in the cloud deployment is not allowing connections to this host on port 443, you will need to check with your cloud administrator or network team to allow this traffic 

DanScho
Visitor

hmm... not good... is it not possible to configure this in azure databricks by myself?

Walter_C
Databricks Employee
Databricks Employee

Unfortunately no because this is not being blocked by Databricks, this is being blocked by a firewall or security group at the cloud level

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group