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

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 快手联盟怎么快速的跑出建立模型
  • ¥20 ros环境下运行orb-slam一直报错
  • ¥15 关于腾讯云服务器中,PHP页面无法打开的问题
  • ¥60 如何把照片修复成原始拍摄图
  • ¥80 Exited too quickly (process log may have details)
  • ¥15 爬知乎登录之后内容加载不出来
  • ¥15 怎么用protues测量通频带
  • ¥15 zepelin使用sparkInterpreter 异常
  • ¥15 paho mqtt 接收不到消息
  • ¥15 函数r关于两个分量y,z方向上的图像,分开画r随y的图像,r随z的图像