bryanyang0528/ksql-python

SELECT statements call incorrect endpoint for KSQLDB 0.19.0

Closed this issue · 1 comments

Queries like:

from ksql import KSQLAPI
client = KSQLAPI('http://localhost:8088')
client.ksql('SELECT * FROM stream_name EMIT CHANGES LIMIT 5;')

don't work and throw the following error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ksql/api.py", line 170, in _request
    r = urllib.request.urlopen(req, timeout=self.timeout)
  File "/usr/local/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/usr/local/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/usr/local/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/ksql/client.py", line 43, in ksql
    return self.sa.ksql(ksql_string, stream_properties=stream_properties)
  File "/usr/local/lib/python3.9/site-packages/ksql/api.py", line 65, in ksql
    r = self._request(endpoint="ksql", sql_string=ksql_string, stream_properties=stream_properties)
  File "/usr/local/lib/python3.9/site-packages/ksql/api.py", line 178, in _request
    raise KSQLError(content.get("message"), content.get("error_code"), content.get("stackTrace"))
ksql.errors.KSQLError: ("The following statement types should be issued to the websocket endpoint '/query':\n\t* PRINT\n\t* SELECT", 40002, None)

P.S. Queries like

client.ksql('SHOW STREAMS;')

work fine.

If anyone else encounters the same issue, It was my mistake.
I should have used

client.query('SELECT * FROM stream_name EMIT CHANGES LIMIT 5;')

instead of

client.ksql('SELECT * FROM stream_name EMIT CHANGES LIMIT 5;')