我正在尝试将JSON直接通过URL传递给communicate with the Ecobe API。无论我如何尝试格式化数据,它都会在URL中转义。用于允许您在调用中传递配置参数的请求,并具有关闭编码的选项,但它已被删除(因此answer in this thread不再工作)。我在文档中看到的唯一引用是requests.defaults中的内容,但我不知道如何设置它。正因为如此,我的URL包含了所有JSON格式的URL转义,而不是API想要的样子:
GET https://api.ecobee.com/1/runtimeReport?format=json&body={"startDate": "2010-01-01","endDate": "2010-01-02","columns": "zoneHVACmode,zoneCalendarEvent","selection":{"selectionType":"thermostats","selectionMatch": 123456789012"}}此外,我已经尝试了足够多的猎枪方法(包括one in this thread),我不确定如果它确实有效,什么是最好/最有效的方法,所以这里是我当前代码的(缩写版本),以防有更好的选择:
self.api_url = 'https://api.ecobee.com/%s?format=json&%s'
data = {
'startDate': start_date.strftime('%Y-%m-%d'),
'endDate': end_date.strftime('%Y-%m-%d'),
'columns': 'auxHeat1,compCool1,outdoorHumidity,zoneAveTemp,zoneCoolTemp,zoneHeatTemp',
'includeSensors': 'true',
'selection': self.selection_info
}
endpoint = 'runtimeReport'
params_json = simplejson.dumps(params)
response = requests.get(self.api_url % (endpoint, params_json), headers=self._get_headers())发布于 2013-07-31 09:20:19
看起来不能再继续下去了。每个URL都通过requote_uri in utils.py传递。除非我遗漏了什么,否则这个API需要在GET参数中包含空格的JSON不是一个好主意。
https://stackoverflow.com/questions/17935559
复制相似问题