boxUpdate.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:Mohou_Box-master 作者: mohou 项目源码 文件源码
def get(self):
        is_on_line = machine_is_online()

        cur_client = HTTPClient()
        response = cur_client.fetch("http://127.0.0.1:5000/status", request_timeout=10)
        if response.error:
            logger.warn("Failed to get current box info. error=%s", response.error)
            is_on_line = False
        res = json_decode(response.body)
        if res["code"] != 0:
            logger.warn("Failed to get current box info. ret_value=%d", res["ret_value"])
            is_on_line = False

        if is_on_line:
            boxid = res["data"]["boxid"]
            params=urllib.urlencode({
                        "token": "box_setting",
                        "boxid": boxid,
                        "progress": 2
                        })
            headers = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Connection": "Keep-Alive"}
            conn = httplib.HTTPConnection("yun.mohou.com")
            conn.request(method="POST", url="/api/box/init-setting", body=params, headers=headers)
            response = conn.getresponse()
            response_json = response.read()
            conn.close()
            logger.info("Box setting result: " + str(response_json))
            is_access_cloud = True
        else:
            is_access_cloud = False
        return self.write({'code': 0, 'msg': 'Success', 'data': {'is_access_cloud': is_access_cloud}})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号