0

我在 chromium 实例上出现白屏,同时尝试使用回调函数来验证我的代理。这是我的代码:

def main():
check_versions()
sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
applicationSettings = {
    "unique_request_context_per_browser": 1,
    "ignore_certificate_errors": 1,
    "persist_session_cookies": 1,
    "persist_user_preferences": 1,
    "string_encoding": "utf-8",
    "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36",
    "context_menu": {
        "enabled": True,
        "navigation": True,
        "print": True,
        "view_source": True,
        "external_browser": True,
        "devtools": True,
    }

}
commandLineSwitches = {
    "proxy-server": "host:port",
    "force-webrtc-ip-handling-policy": "default_public_interface_only",
}
cef.Initialize(applicationSettings, commandLineSwitches)
browser = cef.CreateBrowserSync(url="https://www.google.com/",
                      window_title="Hello World!")
browser.SetClientHandler(RequestHandler("username", "password"))
cef.MessageLoop()
del browser
cef.Shutdown()


class RequestHandler(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password

    def GetAuthCredentials(self, browser, is_proxy, **_):
        if is_proxy:
            resp = _['callback'].Continue(self.username, self.password)
            print(_)
            print(resp)
            return True
        return False


def check_versions():
    ver = cef.GetVersion()
    print("[hello_world.py] CEF Python {ver}".format(ver=ver["version"]))
    print("[hello_world.py] Chromium {ver}".format(ver=ver["chrome_version"]))
    print("[hello_world.py] CEF {ver}".format(ver=ver["cef_version"]))
    print("[hello_world.py] Python {ver} {arch}".format(
       ver=platform.python_version(),
       arch=platform.architecture()[0]))
assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"


if __name__ == '__main__':
    main()

这就是我在命令行中得到的(无限循环):

{'frame': <cefpython_py39.PyFrame object at 0x0000023E38F0B380>, 'host': 'host', 'port': port, 'realm': 'Invalid proxy credentials or missing IP Authorization.', 'scheme': 'basic', 'callback': <cefpython_py39.PyAuthCallback object at 0x0000023E36A87E30>}
None
{'frame': <cefpython_py39.PyFrame object at 0x0000023E38F0B3C0>, 'host': 'host', 'port': port, 'realm': 'The proxy you are connecting is not in your list.', 'scheme': 'basic', 'callback': <cefpython_py39.PyAuthCallback object at 0x0000023E36A87E30>}
None
{'frame': <cefpython_py39.PyFrame object at 0x0000023E38F0B3C0>, 'host': 'host', 'port': port, 'realm': 'The proxy you are connecting is not in your list.', 'scheme': 'basic', 'callback': <cefpython_py39.PyAuthCallback object at 0x0000023E36A87E30>}
None

找不到任何可行的解决方案。也许我错过了一些明显的东西,提前感谢您的帮助!

4

1 回答 1

1

我正在搜索工作代码来测试 GetAuthCredentials,我可以确认它工作正常,没有任何问题。当它工作时,“领域”返回值包含代理横幅(类似于“来自 $vendor 的宏伟代理!”)。

因此,它包含“您正在连接的代理不在您的列表中”是不合逻辑的,因为经过身份验证的代理没有理由检查可能包含或不包含自身的用户列表。

OTOH 在 Windows 下,个人防火墙可以拥有授权代理列表,并且不允许随机程序连接到它。这将是此类消息的正当理由。

于 2021-10-04T14:27:08.390 回答