Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2024 08:06 AM
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