KSQLDB REST API: cURL works, httpx/requests libs do not

I managed to realize the consumption of the KSQLDB PUSH query with the requests library. Here the stream argument does the trick. If I find out what is the trick with httpx, I’ll post it.

import requests

url = “http://localhost:8088/query-stream
headers = {
“Content-Type”: “application/vnd.ksql.v1+json”,
“Accept”: “application/vnd.ksql.v1+json”,
}

data = {
“sql”: “SELECT * FROM stream_temperature_measurements EMIT CHANGES;”,
“streamsProperties”: {}
}

response = requests.post(url, json=data, headers=headers, stream=True)

if response.status_code == 200:
try:
for line in response.iter_lines():
if line:
print(line.decode(‘utf-8’))
except KeyboardInterrupt:
print(“Interrupted by user”)
else:
print(f"Failed to execute query: {response.status_code}")
print(response.text)