Skip to content

Commit 1202aad

Browse files
author
aviau
committed
Merge branch 'master' of github.com:influxdb/influxdb-python
Conflicts: influxdb/client.py
2 parents 9d2a290 + 4aba3c1 commit 1202aad

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

influxdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
__all__ = ['InfluxDBClient']
66

7-
__version__ = '0.1.7'
7+
__version__ = '0.1.8'

influxdb/client.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@
77
import requests
88
session = requests.Session()
99

10+
class InfluxDBClientError(Exception):
11+
"Raised when an error occures in the Request"
12+
def __init__(self, message, code):
13+
self.message = message
14+
self.code = code
1015

1116
class InfluxDBClient(object):
1217
"""
1318
InfluxDB Client
1419
"""
1520

16-
def __init__(
17-
self,
18-
host='localhost',
19-
port=8086,
20-
username='root',
21-
password='root',
22-
database=None,
23-
ssl=False,
24-
verify_ssl=False,
25-
use_udp=False,
26-
udp_port=4444):
27-
21+
def __init__(self,
22+
host='localhost',
23+
port=8086,
24+
username='root',
25+
password='root',
26+
database=None,
27+
ssl=False,
28+
verify_ssl=False,
29+
timeout=0,
30+
use_udp=False,
31+
udp_port=4444):
2832
"""
2933
Initialize client
3034
"""
@@ -33,6 +37,7 @@ def __init__(
3337
self._username = username
3438
self._password = password
3539
self._database = database
40+
self._timeout = timeout
3641

3742
self._verify_ssl = verify_ssl
3843

@@ -105,14 +110,16 @@ def request(self, url, method='GET', params=None, data=None,
105110
params=params,
106111
data=data,
107112
headers=self._headers,
108-
verify=self._verify_ssl
113+
verify=self._verify_ssl,
114+
timeout=self._timeout
109115
)
110116

111117
if response.status_code == status_code:
112118
return response
119+
113120
else:
114-
raise Exception(
115-
"{0}: {1}".format(response.status_code, response.content))
121+
error = InfluxDBClientError("{0}: {1}".format(response.status_code, response.content), response.status_code)
122+
raise error
116123

117124
# Writing Data
118125
#
@@ -273,7 +280,13 @@ def query(self, query, time_precision='s', chunked=False):
273280
status_code=200
274281
)
275282

276-
return json.loads(response.content)
283+
try:
284+
res = json.loads(response.content)
285+
except TypeError:
286+
# must decode in python 3
287+
res = json.loads(response.content.decode('utf8'))
288+
289+
return res
277290

278291
# Creating and Dropping Databases
279292
#

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy