Example #1
0
 def _get_json(self, post_data):
     if post_data['op'] == 'login':
         data = {}
     else:
         data = {'sid': self.sid}
     data.update(post_data)
     r = self._session.post(self.url, data=json.dumps(data))
     raise_on_error(r)
     return json.loads(r.content)
Example #2
0
    def response_hook(self, r, **kwargs):
        j = json.loads(r.content)
        if int(j["status"]) == 0:
            return r

        self.sid = self._get_sid(r.request.url)

        r.request.deregister_hook("response", self.response_hook)
        j = json.loads(r.request.body)
        j.update({"sid": self.sid})
        req = requests.Request("POST", r.request.url)
        req.data = json.dumps(j)
        _r = requests.Session().send(req.prepare())
        raise_on_error(_r)

        return _r
Example #3
0
 def _get_sid(self, url):
     res = requests.post(url, data=json.dumps({"op": "login", "user": self.user, "password": self.password}))
     raise_on_error(res)
     j = json.loads(res.content)
     return j["content"]["session_id"]