bryanyang0528 / ksql-python

A python wrapper for the KSQL REST API.
MIT License
159 stars 64 forks source link

IndexError after inserting #80

Open agmo1993 opened 4 years ago

agmo1993 commented 4 years ago

i'm receiving the following error after inserting into a stream using

client.ksql("INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ab5cbad', 37.3952, -122.0813);")`

Traceback (most recent call last): File "", line 1, in File "/home/ubuntu/.local/lib/python3.6/site-packages/ksql/client.py", line 42, in ksql return self.sa.ksql(ksql_string, stream_properties=stream_properties) File "/home/ubuntu/.local/lib/python3.6/site-packages/ksql/api.py", line 64, in ksql self._raise_for_status(r, response) File "/home/ubuntu/.local/lib/python3.6/site-packages/ksql/api.py", line 54, in _raise_for_status if r_json[0]["@type"] == "currentStatus" and r_json[0]["commandStatus"]["status"] == "ERROR": IndexError: list index out of range

Although the insert is successful and I can view it on a select query, any ideas about what's causing it to throw an error?

bryanyang0528 commented 4 years ago

@agmo1993 Thank you for reporting issue. I will check the API response.

romainr commented 4 years ago

Indeed, I see the same.

Seems like we get []

romainr commented 4 years ago

Not sure if it is the best way to fix it but it avoids it

https://github.com/bryanyang0528/ksql-python/pull/88

bryanyang0528 commented 3 years ago

@romainr Thank you for fixing it. Good contribution!

bryanyang0528 commented 3 years ago

@agmo1993 Please try if this fixes this issue. Thank you.

javiersvg commented 3 years ago

I had the same issue and this solved it. When do you think will this be released?

ozair-junior commented 3 years ago

While we are waiting, I make this local correction :wink: :


class KsqlApiCustom(KSQLAPI):
    def __init__(self, url, max_retries=3, check_version=True, **kwargs):
        super().__init__(url, max_retries=max_retries,
                         check_version=check_version, **kwargs)
        self.sa._raise_for_status = self._raise_for_status

    @staticmethod
    def _raise_for_status(r, response):
        r_json = json.loads(response)
        if r.getcode() != 200:
            # seems to be the new API behavior
            if r_json.get("@type") == "statement_error" or r_json.get("@type") == "generic_error":
                error_message = r_json["message"]
                error_code = r_json["error_code"]
                stackTrace = r_json["stack_trace"]
                raise KSQLError(error_message, error_code, stackTrace)
            else:
                raise KSQLError("Unknown Error: {}".format(r.content))
        else:
            # seems to be the old API behavior, so some errors have status 200, bug??
            if r_json and r_json[0]["@type"] == "currentStatus" and r_json[0]["commandStatus"]["status"] == "ERROR":
                error_message = r_json[0]["commandStatus"]["message"]
                error_code = None
                stackTrace = None
                raise KSQLError(error_message, error_code, stackTrace)
            return True
KenCox94 commented 2 years ago

should be seeing a new release relatively soon. @bryanyang0528 is hard at work on updating the project. thanks for your patience.

rgbarry commented 2 years ago

Thank you @ozair-junior !!!