flyfishes / ctyun_keepalive

天翼云电脑自动连接保活,阻止休眠
GNU General Public License v3.0
12 stars 1 forks source link

try to run with Ubuntu 24.04 minimal but need guide #5

Open laris opened 2 months ago

laris commented 2 months ago

尝试在ubuntu 24.04 minimal 安装,还是没成功,有没有headless的实践方案?

$ apt install -y chromium-chromedriver python3-selenium python3-requests python3-pyvirtualdisplay python3-flask
$ dpkg -L chromium-chromedriver|grep bin
/usr/bin/chromedriver
$ dpkg -L chromium-browser|grep bin
/usr/bin/chromium-browser

Error

/usr/bin/chromedriver
--------------------------------------------------------------------------------
root@ubuntu:~/ctyun_keepalive-main# python3 ctyun-alive.py 13xxxxxx "passwd" chromium /usr/bin/chromedriver
/root/ctyun_keepalive-main/ctyun-alive.py:104: SyntaxWarning: invalid escape sequence '\P'
  options.binary_location='C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' if (parms['browserPath']=='') else parms['browserPath']
/root/ctyun_keepalive-main/ctyun-alive.py:107: SyntaxWarning: invalid escape sequence '\p'
  options.binary_location='D:\programs\chrome\chrome.exe' if (parms['browserPath']=='') else parms['browserPath']
未发现my.json配置文件,或配置文件格式有误。
{'account': '13xxxxxx', 'password': 'passwd', 'browserType': 'chromium', 'browserPath': '/usr/bin/chromedriver', 'listenport': 8000, 'listen_url': '', 'push_token': ''}
[keepalive_ctyun]try start selenium
 * Serving Flask app 'webthread'
 * Debug mode: off
[keepalive_ctyun]Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 89, in driver_location
    args = [str(self.get_binary()), "--browser", browser]
                ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 73, in get_binary
    raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}")
selenium.common.exceptions.WebDriverException: Message: Unable to obtain working Selenium Manager binary; /usr/lib/python3/dist-packages/selenium/webdriver/common/linux/selenium-manager

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/ctyun_keepalive-main/ctyun-alive.py", line 108, in keepalive_ctyun2
    driver = webdriver.Chrome(options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/lib/python3/dist-packages/selenium/webdriver/chromium/webdriver.py", line 49, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

Traceback (most recent call last):
  File "/root/ctyun_keepalive-main/ctyun-alive.py", line 255, in <module>
    ret=keepalive_ctyun2(parms=parms)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ctyun_keepalive-main/ctyun-alive.py", line 181, in keepalive_ctyun2
    driver.get_screenshot_as_file('static/ctyun.png')
    ^^^^^^
UnboundLocalError: cannot access local variable 'driver' where it is not associated with a value

--------------------------------------------------------------------------------
/usr/bin/chromium-browser
--------------------------------------------------------------------------------
root@ubuntu:~/ctyun_keepalive-main# python3 ctyun-alive.py 13xxxxxx "passwd"  chromium /usr/bin/chromium-browser
/root/ctyun_keepalive-main/ctyun-alive.py:104: SyntaxWarning: invalid escape sequence '\P'
  options.binary_location='C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' if (parms['browserPath']=='') else parms['browserPath']
/root/ctyun_keepalive-main/ctyun-alive.py:107: SyntaxWarning: invalid escape sequence '\p'
  options.binary_location='D:\programs\chrome\chrome.exe' if (parms['browserPath']=='') else parms['browserPath']
未发现my.json配置文件,或配置文件格式有误。
{'account': '13xxxxxx', 'password': 'passwd', 'browserType': 'chromium', 'browserPath': '/usr/bin/chromium-browser', 'listenport': 8000, 'listen_url': '', 'push_token': ''}
 * Serving Flask app 'webthread'
[keepalive_ctyun]try start selenium
 * Debug mode: off
[keepalive_ctyun]Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 89, in driver_location
    args = [str(self.get_binary()), "--browser", browser]
                ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 73, in get_binary
    raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}")
selenium.common.exceptions.WebDriverException: Message: Unable to obtain working Selenium Manager binary; /usr/lib/python3/dist-packages/selenium/webdriver/common/linux/selenium-manager

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/ctyun_keepalive-main/ctyun-alive.py", line 108, in keepalive_ctyun2
    driver = webdriver.Chrome(options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/lib/python3/dist-packages/selenium/webdriver/chromium/webdriver.py", line 49, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

Traceback (most recent call last):
  File "/root/ctyun_keepalive-main/ctyun-alive.py", line 255, in <module>
    ret=keepalive_ctyun2(parms=parms)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ctyun_keepalive-main/ctyun-alive.py", line 181, in keepalive_ctyun2
    driver.get_screenshot_as_file('static/ctyun.png')
    ^^^^^^
UnboundLocalError: cannot access local variable 'driver' where it is not associated with a value
flyfishes commented 1 week ago

你这个是配置文件参数不对,就是默认的chrome安装位置要设置,位置包括chrome.exe浏览器的(不是chromedriver.exe的,单纯chromedriver好像不行) 'browserPath': '/usr/bin/chromedriver',