我正在为一个需要在一段时间内从涌入中查询数据的过程构建一个有点自动化的查询构建器。为此,我需要按时间过滤,这意味着我的查询中需要纪元毫秒字符串。此代码引发以下错误。
import pandas as pd
ts = pd.Timestamp(pd.Timestamp('now', tz='US/Pacific').date(), tz='US/Pacific')
ts_str = str(int(ts.value / (10 ** 6)))
query_str = 'SELECT * FROM "table"."measurement" WHERE time <= ' + \
ts_str + 'ms LIMIT 10'
json_payload = client.query(query_str)
print(json_payload)
和堆栈跟踪:
Traceback (most recent call last):
File "my_code.py", line 31, in query
return self.client.query(query)
File "/usr/local/lib/python2.7/site-packages/influxdb/_dataframe_client.py", line 138, in query
results = super(DataFrameClient, self).query(query, database=database)
File "/usr/local/lib/python2.7/site-packages/influxdb/client.py", line 339, in query
expected_response_code=expected_response_code
File "/usr/local/lib/python2.7/site-packages/influxdb/client.py", line 239, in request
timeout=self._timeout
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 474, in request
prep = self.prepare_request(req)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 407, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 302, in prepare
self.prepare_url(url, params)
File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 426, in prepare_url
enc_params = self._encode_params(params)
File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 104, in _encode_params
return urlencode(result, doseq=True)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1353, in urlencode
v = quote_plus(v)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1308, in quote_plus
s = quote(s, safe + ' ')
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1303, in quote
return ''.join(map(quoter, s))
KeyError: 83