| 290 | return other_data |
| 291 | |
| 292 | def _request(self, path: str, action: str, pdata: dict = None) -> Tuple[Optional[any], str]: |
| 293 | url = "{}{}".format(self.origin, path) |
| 294 | pdata = pdata or {} |
| 295 | bt_p = self.get_bt_params({"action": action, **pdata}) |
| 296 | header = { |
| 297 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 298 | "User-Agent": "Bt-Panel/Node Manager" |
| 299 | } |
| 300 | try: |
| 301 | resp = requests.post(url, data=bt_p, headers=header, verify=False, timeout=self.timeout) |
| 302 | if not resp.status_code == 200: |
| 303 | return None, "响应状态码错误,请检查节点地址和api是否正确,目前响应状态码为{}".format( |
| 304 | resp.status_code) |
| 305 | if self.app_key: |
| 306 | real_data = public.aes_decrypt(resp.text, self.app_key.app_key) |
| 307 | return json.loads(real_data), "" |
| 308 | return resp.json(), "" |
| 309 | except Exception as e: |
| 310 | # public.print_error() |
| 311 | # return None, "请求节点失败,请检查节点地址和api是否正确,错误信息为:{}".format(str(e)) |
| 312 | if self.remarks: |
| 313 | return None, "请求节点【{}】失败,请检查节点地址和api是否正确".format(self.remarks) |
| 314 | return None, "请求节点失败,请检查节点地址和api是否正确" |
| 315 | |
| 316 | def get_file_body(self, path: str) -> Tuple[Optional[str], str]: |
| 317 | data, err = self._request("/files", "GetFileBody", pdata={"path": path}) |