maximdanilchenko / aiochclient

Lightweight async http(s) ClickHouse client for python 3.6+ with types converting
https://aiochclient.readthedocs.io
MIT License
248 stars 46 forks source link

ClickHouse error: Unrecognized type name: '<html>' #115

Open Vikram1802 opened 8 months ago

Vikram1802 commented 8 months ago

I'm running this simple query but getting the KeyError: '<html>'

async def fetch_data():
    try:
        async with aiohttp.ClientSession() as s:
            client = ChClient(s, url, user=user, password, compress_response=True)
            alive = await client.is_alive()
            print(f"Is ClickHouse alive? -> {alive}")
            fetch = await client.fetch("select id from customers where id > 200 limit 10")
            print(f"{fetch}")
    except ChClientError as e:
        print("ClickHouse error: {}".format(e))

Error:

KeyError: '<html>'

During handling of the above exception, another exception occurred:

ChClientError                             Traceback (most recent call last)
Cell In[23], line 5
      5 alive = await client.is_alive()
      6 print(f"Is ClickHouse alive? -> {alive}")
----> 7 fetch = await client.fetch("select id from customers where id > 200 limit 10")
       8 print(f"{fetch}")
File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/client.py:265, in ChClient.fetch(self, query, json, params, query_id, decode, *args)
    239 async def fetch(
    240     self,
    241     query: str,
   (...)
    246     decode: bool = True,
    247 ) -> List[Record]:
    248     """Execute query and fetch all rows from query result at once in a list.
    249 
    250     :param query: Clickhouse query string.
   (...)
    263     :return: All rows from query.
    264     """
--> 265     return [
    266         row
    267         async for row in self._execute(
    268             query,
    269             *args,
    270             json=json,
    271             query_params=params,
    272             query_id=query_id,
    273             decode=decode,
    274         )
    275     ]

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/client.py:265, in <listcomp>(.0)
    239 async def fetch(
    240     self,
    241     query: str,
   (...)
    246     decode: bool = True,
    247 ) -> List[Record]:
    248     """Execute query and fetch all rows from query result at once in a list.
    249 
    250     :param query: Clickhouse query string.
   (...)
    263     :return: All rows from query.
    264     """
--> 265     return [
    266         row
    267         async for row in self._execute(
    268             query,
    269             *args,
    270             json=json,
    271             query_params=params,
    272             query_id=query_id,
    273             decode=decode,
    274         )
    275     ]

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/client.py:184, in ChClient._execute(self, query, json, query_params, query_id, decode, *args)
    182         yield rf.new(line)
    183 else:
--> 184     rf = RecordsFabric(
    185         names=await response.__anext__(),
    186         tps=await response.__anext__(),
    187         convert=decode,
    188     )
    189     async for line in response:
    190         yield rf.new(line)

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/records.py:91, in RecordsFabric.__init__(self, tps, names, convert)
     89 self.names = {key: index for (index, key) in enumerate(names)}
     90 if convert:
---> 91     self.converters = [
     92         what_py_converter(tp) for tp in tps.decode().strip().split("\t")
     93     ]
     94 else:
     95     self.converters = [
     96         empty_convertor for _ in tps.decode().strip().split("\t")
     97     ]

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/records.py:92, in <listcomp>(.0)
     89 self.names = {key: index for (index, key) in enumerate(names)}
     90 if convert:
     91     self.converters = [
---> 92         what_py_converter(tp) for tp in tps.decode().strip().split("\t")
     93     ]
     94 else:
     95     self.converters = [
     96         empty_convertor for _ in tps.decode().strip().split("\t")
     97     ]

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/_types.pyx:814, in aiochclient._types.what_py_converter()

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/_types.pyx:816, in aiochclient._types.what_py_converter()

File ~/volume/clickhouse/.venv/lib/python3.9/site-packages/aiochclient/_types.pyx:811, in aiochclient._types.what_py_type()

ChClientError: Unrecognized type name: '<html>'
Maksim-Burtsev commented 8 months ago

Hi, @Vikram1802 !

Can you show DESCRIBE TABLE customers and tell what version of aiochclient you use in this example? And do you have any proxy like nginx/chproxy/etc.?

Looks like there is problem with ClickHouse or proxy (not library) and full result of http request will be look like "502" or something like that.