【问题标题】:selenium automation signing to google cloud throws networks error硒自动化签名到谷歌云引发网络错误
【发布时间】:2022-11-13 19:30:41
【问题描述】:

我在我的项目中使用硒和硒线。我正在编写流程以登录谷歌云门户网站..

然后我输入我的谷歌云邮件,在谷歌登录中按继续,然后登录 gcp。

我遇到了一些错误:

请求具有无效的身份验证凭据。预期的 OAuth 2 访问令牌、登录 cookie 或其他...

净::ERR_PROXY_CONNECTION_FAILED

当我做同样的流程时手动如果没有自动化,使用相同的凭据,它可以正常工作并且没有任何网络错误。

我的网络驱动程序

from seleniumwire import webdriver
from seleniumwire.webdriver import ChromeOptions

def test_gcp_flow():

    options = ChromeOptions()
    options.add_experimental_option("detach", True)
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument("--start-maximized")
    options.add_argument('--auto-open-devtools-for-tabs')
    options.add_argument('--log-level=2')
    options.add_argument('--disable-features=IsolateOrigins,site-per-process')
    options.add_argument("--ignore_ssl")
    options.add_argument('--ignore-ssl-errors')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument("--disable-extensions")
    options.add_argument("--disable-setuid-sandbox")
    options.add_argument("--dns-prefetch-disable")
    options.add_argument('ignore-certificate-errors')
    options.add_argument('disable-web-security')
    options.add_argument('--allow-insecure-localhost')

    driver = webdriver.Chrome(options=options)
    driver.get('....any-hidden-url')
    # more flow actions - then it open gcp portal
    

我添加了 openssl.cnf(没有这个 openssl,它向我显示 TLS ssl 问题)以在我使用 Pycharm 的测试中本地运行它:

openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
Options = UnsafeLegacyRenegotiation

我试图添加一些更改添加到 selenium 驱动程序的 chrome 选项,但没有任何改变,仍然是同样的错误。

我尝试使用 Firefox webdriver,它运行良好,没有任何网络问题。也许这是任何 chrome 缓存问题?因为几天前它对我有用 chrome..

我期望的是登录 gmail 没有网络/令牌问题。

【问题讨论】:

    标签: selenium selenium-webdriver google-cloud-platform selenium-chromedriver e2e-testing


    【解决方案1】:

    我可以想到两种可能的选择:

    1. 出于安全原因,Google 会检测到 Selenium 并阻止使用它登录。 Selenium Web 驱动程序将可识别的 javascript 注入浏览器,您可以使用简单的脚本检测它。

    2. 您的浏览器中有一个不与 Selenium 一起使用的身份验证 cookie。 每个 Selenium 会话都以完全干净的方式启动自身。例如,您可以使用 pickle 保存您的 cookie,然后使用 Python 将其注入 Selenium Web 驱动程序。尽管如果您无法将其加密存储在安全的地方并在运行时获取它,我会避免使用它(否则-在某些时候,无论您认为自己有多安全,它都会被盗)。

      顺便说一句,如果它是你真正需要的东西——你是付费客户,也许谷歌有这种需求的可用解决方案。

      祝你好运!

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 2020-07-19
      • 2020-01-01
      相关资源
      最近更新 更多