Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 8dd8933

Browse files
authored
Merge pull request #66 from datafuselabs/fix/empty-response-exception
fix: handle empty response content
2 parents 80b0344 + 418c604 commit 8dd8933

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

databend_py/connection.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,21 @@ def do_query(self, url, query_sql):
135135
auth=HTTPBasicAuth(self.user, self.password),
136136
timeout=(self.connect_timeout, self.read_timeout),
137137
verify=True)
138-
try:
139-
resp_dict = json.loads(response.content)
140-
except json.decoder.JSONDecodeError:
141-
raise UnexpectedException("failed to parse response: %s" % response.content)
142-
if resp_dict and resp_dict.get('error') and "no endpoint" in resp_dict.get('error'):
143-
raise WarehouseTimeoutException
144-
if resp_dict and resp_dict.get('error'):
145-
raise UnexpectedException("failed to query: %s" % response.content)
146-
if self.persist_cookies:
147-
self.cookies = response.cookies
148-
return resp_dict
138+
139+
if response.content:
140+
try:
141+
resp_dict = json.loads(response.content)
142+
except ValueError:
143+
raise UnexpectedException("failed to parse response: %s" % response.content)
144+
if resp_dict and resp_dict.get('error') and "no endpoint" in resp_dict.get('error'):
145+
raise WarehouseTimeoutException
146+
if resp_dict and resp_dict.get('error'):
147+
raise UnexpectedException("failed to query: %s" % response.content)
148+
if self.persist_cookies:
149+
self.cookies = response.cookies
150+
return resp_dict
151+
else:
152+
raise UnexpectedException("response content is empty: %s" % response)
149153

150154
def query(self, statement):
151155
url = self.format_url()

databend_py/defines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
DEFAULT_USER = 'root'
33
DEFAULT_PASSWORD = ''
44
DEFAULT_SESSION_IDLE_TIME = 30
5-
DEFAULT_CONNECT_TIMEOUT = 20
6-
DEFAULT_READ_TIMEOUT = 20
5+
DEFAULT_CONNECT_TIMEOUT = 180
6+
DEFAULT_READ_TIMEOUT = 180
77

88
DBMS_NAME = 'Databend'
99
CLIENT_NAME = 'databend-py'

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def test_simple(self):
4646
self.assertEqual(c.connection.schema, "http")
4747
c = Client.from_url("databend://root:root@localhost:8000/default?compress=True")
4848
self.assertEqual(c._uploader._compress, True)
49-
self.assertEqual(c.connection.connect_timeout, 20)
50-
self.assertEqual(c.connection.read_timeout, 20)
49+
self.assertEqual(c.connection.connect_timeout, 180)
50+
self.assertEqual(c.connection.read_timeout, 180)
5151

5252
c = Client.from_url("databend://root:root@localhost:8000/default?connect_timeout=30&read_timeout=30")
5353
self.assertEqual(c.connection.connect_timeout, 30)

0 commit comments

Comments
 (0)