0

I get white screen on the chromium instance, while trying to make callback function to authenticate my proxies. Here is my code for that:

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()

That's what i get in the command line (infinite loop):

{'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

Cannot find any working solution for that. Maybe i'm missing something obvious, thanks for help in advance!

hen
  • 65
  • 1
  • 7

1 Answers1

1

I was searching working code to test GetAuthCredentials and I can confirm that it is working fine, nothing wrong with it. When it works, the 'realm' returned value contains the proxy banner (something along the lines of 'magnificent proxy from $vendor!').

So for it to contain 'The proxy you are connecting is not in your list' is not logical, because there is no reason that an authenticated proxy should check against a user list that could include or not itself.

OTOH under Windows, a personal firewall could have a list of authorized proxies and not allow a random program to connect to it. That would be a valid reason for such message.

gerard
  • 11
  • 1