I am trying to create a connector to the Kaiterra API. the authentication scheme asks to send your key in a URL parameter called key.
I am new to the Fantom WebClient class so am trying to figure out. Based on the postForm documentation, it looks like this does most of the work for sending parameters. When I run my code, I get the following:
como Fri 31 Aug 2018
Hello Fantom Users,
I am trying to create a connector to the Kaiterra API. the authentication scheme asks to send your key in a URL parameter called
key.I am new to the Fantom WebClient class so am trying to figure out. Based on the postForm documentation, it looks like this does most of the work for sending parameters. When I run my code, I get the following:
The code is very simple, so maybe I am missing something.
using web ** ** Working with WebClient ** class Client { Void main() { tester } Void tester() { // simple string get echo("\n--- getStr ---") myClient := WebClient(`https://api.origins-china.cn/v1/sensedges/<my_uuid>`) myClient.postForm(["key":"<my-key>"]) echo(myClient.resStr) myClient.close } }I have python code that works as follows:
class CallKaiterra(): def __init__(self, key, devices): self.key = key self.base_url = "https://api.origins-china.cn/v1/sensedges/" self.devices = devices self.headers = {'Accept-Encoding': 'gzip', 'Content-Encoding': 'UTF-8'} self.params = {'key': self.key} self.hist_params = {'key': self.key, 'series': 'raw'} self.data = {} def call(self, id, type): if type == "cur": response = requests.get(self.base_url + id, headers = self.headers, params = self.params) elif type == "hist": response = requests.get(self.base_url + id + "/history", headers = self.headers, params = self.hist_params) return response def get_cur_data(self): for k, v in self.devices.items(): response = self.call(v, "cur") if response.status_code == 200: self.data[k] = json.loads(response.text) def get_hist_data(self, end, begin=None, limit=None): self.end = end if limit: self.params['limit'] = limit if begin: self.params['begin'] = begin response = self.call(self.devices["Boulder"], "hist") self.data["Boulder"] = json.loads(response.text) if __name__ == '__main__': devices = {"Boulder": '<uuid_boulder>', "New York": '<uuid_new_york>'} c = CallKaiterra("<my_key>", devices)If anybody has any insight, would be appreciated. Thanks.
brian Fri 31 Aug 2018
It looks like the response is gzipped incorrectly.
I'd suggest using generic tool to dump the headers and see what they look like and if they server is saying the content is gzip encoded