The 500 error is an internal problem on the server side of your application.
You may check this thread : https://learn.microsoft.com/en-us/answers/questions/547714/serverless-sql-pool-has-encountered-an-internal-er
I will add the fact that adding a handling error part can give you more insights into what went wrong to check whether your query is correct and compatible with the Serverless SQL pool.
Also here is a sample code to authenticate and make a REST API request to query data from the Serverless SQL pool:
import requests
import json
# Azure app registration details
tenant_id = "<Your Tenant ID>"
client_id = "<Your Client ID>"
client_secret = "<Your Client Secret>"
# Get the Azure token
token_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
token_data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'scope': 'https://graph.microsoft.com/.default'
}
token_r = requests.post(token_url, data=token_data)
token = token_r.json().get("access_token")
# Synapse workspace details
workspace_name = "<Your Workspace Name>"
sql_endpoint = f"https://{workspace_name}.dev.azuresynapse.net"
# SQL Query
sql_query = "SELECT * FROM <Your Table>"
# REST API request to query data
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.post(f"{sql_endpoint}/query", headers=headers, json={"sql": sql_query})
# Check response
if response.status_code == 200:
print(response.json())
else:
print(f"Error: Unable to fetch data. Status code: {response.status_code}")
print(response.text)