def user_login(self): try: ip = self.var_ip.get() port = self.var_port.get() name = self.var_name.get() pwd = self.var_pwd.get() qb = Client(host='http://{ip}:{port}'.format(ip=ip, port=port), username=name, password=pwd) # 测试是否通过 qb.app_version() self.controller.qb = qb self.controller.login_statu = True with open(USER_INFO_PATH, "wb") as usr_file: # with open with语句可以自动关闭资源 usrs_info = { "ip": ip, 'port': port, 'name': name, 'pwd': pwd } # 以字典的形式保存账户和密码 pickle.dump(usrs_info, usr_file) except Exception as exc: tk.messagebox.showerror('Error', '登录失败:%s' % exc)
def test_http401(): client = Client(VERIFY_WEBUI_CERTIFICATE=False) _ = client.app.version # ensure cross site scripting protection is enabled client.app.preferences = dict(web_ui_csrf_protection_enabled=True) # simulate a XSS request with pytest.raises(Unauthorized401Error): client.app_version(headers={"X-Forwarded-Host": "http://example.com"})
def test_http401(): client = Client() _ = client.app.version # ensure cross site scripting protection is enabled client.app.preferences = dict(web_ui_csrf_protection_enabled=True) # simulate a XSS request with pytest.raises(Unauthorized401Error): client.app_version(headers={'X-Forwarded-Host': 'http://example.com'})
def test_request_retry_success(monkeypatch, caplog): def request500(*arg, **kwargs): raise exceptions.HTTP500Error() client = Client(VERIFY_WEBUI_CERTIFICATE=False) _ = client.app.version # do the login first with monkeypatch.context() as m: m.setattr(client, "_request", request500) with caplog.at_level(logging.DEBUG, logger="qbittorrentapi"): with pytest.raises(exceptions.HTTP500Error): client.app_version() assert "Retry attempt" in caplog.text
def _get_client(self): with DBSession() as db: cred = db.query(QBittorrentCredentials).first() if not cred: return False if not cred.port: cred.port = self.DEFAULT_PORT address = self.ADDRESS_FORMAT.format(cred.host, cred.port) client = Client(host=address, username=cred.username, password=cred.password) client.app_version() return client