SampoValo 2022-02-04 19:55 采纳率: 100%
浏览 937
已结题

Selenium关于invalid session id错误

请问一下,我使用Selenium跟Python做网页自动化但是随着几个帐号登入后常会遇到session id invalid的问题导致程序停止
我在执行中已经使用try except去handle所有的错误了但是还是无法解决这个问题

标识错误程序码片段

try:
            time.sleep(5)

            # Geetest Image
            self.waitGeetest.until(EC.presence_of_element_located((By.XPATH, '/html/body/div[69]/div[2]/div[6]/div/div[1]/div[2]/div[2]')))
        
        except TimeoutException:
            print('Geetest验证视窗等待超时,验证失败重新启动')
            self.browser.close()
            self.login()
        except NoSuchElementException:
            print('Geetest验证视窗未载入,验证失败重新启动')
            self.browser.close()
            self.login()
        except Exception as e:
            print('Geetest验证视窗开启失败,重新启动...意外发生')
            with open('./data/Error_Record.txt', 'a+', encoding='utf-8') as f:
                f.write('Geetest未知错误: ' + Account + ' 使用代理: ' + self.ProxyString + '\n')
                f.close()
             # 截取当前超时页面画面存档
            self.browser.get_screenshot_as_file('./screenshot//' + self.UserID + '_LoginGeetestError.png')
            self.browser.close()
            self.login()  # 重新启动登入程序
        else:
            print('Geetest窗口已开启,进行自动验证中...')
            self.GeeTest('//*[@id="region-profile-menu"]/div/div[1]/div[1]/div[1]')  # Royalty Icon

错误信息

Traceback (most recent call last):
  File "d:\Programming\Python\StormBot\start.py", line 183, in login
    self.waitGeetest.until(EC.presence_of_element_located((By.XPATH, '/html/body/div[69]/div[2]/div[6]/div/div[1]/div[2]/div[2]')))
  File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
Backtrace:
        Ordinal0 [0x00626903+2517251]
        Ordinal0 [0x005BF8E1+2095329]
        Ordinal0 [0x004C2848+1058888]
        Ordinal0 [0x004ED448+1233992]
        Ordinal0 [0x004ED63B+1234491]
        Ordinal0 [0x00517812+1406994]
        Ordinal0 [0x0050650A+1336586]
        Ordinal0 [0x00515BBF+1399743]
        Ordinal0 [0x0050639B+1336219]
        Ordinal0 [0x004E27A7+1189799]
        Ordinal0 [0x004E3609+1193481]
        GetHandleVerifier [0x007B5904+1577972]
        GetHandleVerifier [0x00860B97+2279047]
        GetHandleVerifier [0x006B6D09+534521]
        GetHandleVerifier [0x006B5DB9+530601]
        Ordinal0 [0x005C4FF9+2117625]
        Ordinal0 [0x005C98A8+2136232]
        Ordinal0 [0x005C99E2+2136546]
        Ordinal0 [0x005D3541+2176321]
        BaseThreadInitThunk [0x7595FA29+25]
        RtlGetAppContainerNamedObjectPath [0x77047A9E+286]
        RtlGetAppContainerNamedObjectPath [0x77047A6E+238]


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\Programming\Python\StormBot\start.py", line 114, in login
    self.browser.get(self.LoginUrl)
  File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 436, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Ricky\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response       
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月16日
  • 已采纳回答 3月8日
  • 创建了问题 2月4日

悬赏问题

  • ¥15 在rhel8中安装qemu-kvm时遇到“cannot initialize crypto:unable to initialize gcrypt“报错”
  • ¥15 arbotix没有/cmd_vel话题
  • ¥15 paddle库安装时报错提示需要安装common、dual等库,安装了上面的库以后还是显示报错未安装,要怎么办呀?
  • ¥20 找能定制Python脚本的
  • ¥15 odoo17的分包重新供应路线如何设置?可从销售订单中实时直接触发采购订单或相关单据
  • ¥15 用C语言怎么判断字符串的输入是否符合设定?
  • ¥15 通信专业本科生论文选这两个哪个方向好研究呀
  • ¥50 我在一个购物网站的排队系统排队,这个排队到号后重新定向到目标网站进行购物,但是有技术牛通过技术方法直接跳过排队系统进入目标网址购物,有没有什么软件或者脚本可以用
  • ¥15 ios可以实现ymodem-1k协议 1024字节传输吗?
  • ¥300 寻抓云闪付tn组成网页付款链接