我在 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
找不到任何可行的解决方案。也许我错过了一些明显的东西,提前感谢您的帮助!