Browse Source

check http response code, if unauthorized, login again

Jelte Jansen 14 years ago
parent
commit
345b81701d
1 changed files with 13 additions and 5 deletions
  1. 13 5
      src/bin/bindctl/bindcmd.py

+ 13 - 5
src/bin/bindctl/bindcmd.py

@@ -217,16 +217,24 @@ class BindCmdInterpreter(Cmd):
         for module_name in self.config_data.get_config_item_list():
         for module_name in self.config_data.get_config_item_list():
             self._prepare_module_commands(self.config_data.get_module_spec(module_name))
             self._prepare_module_commands(self.config_data.get_module_spec(module_name))
 
 
+    def _send_message(self, url, body):
+        headers = {"cookie" : self.session_id}
+        self.conn.request('GET', url, body, headers)
+        res = self.conn.getresponse()
+        return res.status, res.read()
+
     def send_GET(self, url, body = None):
     def send_GET(self, url, body = None):
         '''Send GET request to cmdctl, session id is send with the name
         '''Send GET request to cmdctl, session id is send with the name
         'cookie' in header.
         'cookie' in header.
         '''
         '''
-        headers = {"cookie" : self.session_id}
+        status, reply_msg = self._send_message(url, body)
-        self.conn.request('GET', url, body, headers)
+        if status == http.client.UNAUTHORIZED:
-        res = self.conn.getresponse()
+            if self.login_to_cmdctl():
-        reply_msg = res.read()
+                # successful, so try send again
+                status, reply_msg = self._send_message(url, body)
+            
         if reply_msg:
         if reply_msg:
-           return json.loads(reply_msg.decode())
+            return json.loads(reply_msg.decode())
         else:
         else:
             return {}
             return {}