druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

Error when the error response is in bytes format #192

Open EmadMokhtar opened 4 years ago

EmadMokhtar commented 4 years ago

Overview

We are getting errors from the Druid APIs but it is in a bytes format b''. When the error response passed to the json.loads() it will crash. I think this happening after this PR #121.

Error Details

        except urllib.error.HTTPError as e:
            err = e.read()
            if e.code == 500:
                # has Druid returned an error?
                try:
                    err = json.loads(err)  # ERROR HAPPEN HERE
                except ValueError:
                    if HTML_ERROR.search(err):
                        err = HTML_ERROR.search(err).group(1)
                except (ValueError, AttributeError, KeyError):
                    pass
err = b'{"error":"Unknown exception","errorMessage":"Failure getting results for query[85d259df-c0ea-43c7-93d9-49e609b3b203] url[http://druid/druid/v2/] because of [org.jboss.netty.channel.ChannelException: Channel disconnected]","errorClass":"org.apache.druid.java.util.common.RE","host":null}'

versions

EmadMokhtar commented 4 years ago

I will try to fix this.

Plan

I have a simple plan to fix this issue. I will check if the content of the error message (HTTP response) is in a byte format, then I will decode it.