我正在尝试在 python 中发布查询以从 Kairosdb 获取数据:meterreading 是我已经创建的指标。
import urllib
import urllib2
url = 'http://localhost:8080/api/v1/datapoints/query'
values = {
"start_absolute": "1430454600",
"end_relative": {
"value": "5",
"unit": "days"
},
"metrics": [
{
"tags": {
"phase": [
"769"
],
"uom": [
"72"
]
},
"name": "materreadings",
"aggregators": [
{
"name": "sum",
"sampling": {
"value": "10",
"unit": "minutes"
}
}
]
}
]
}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req) // this line is giving errors
the_page = response.read()
print(the_page)
执行此脚本时,我得到以下结果:
python abc.py
Traceback (most recent call last):
File "abc.py", line 37, in <module>
response = urllib2.urlopen(req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1214, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 61] Connection refused>
当我尝试通过发送请求获得响应时,问题似乎出在第 37 行。我可以在 JAVA 中执行此操作,但在 python 中我被卡住了。我是不是错过了什么。