【发布时间】:2020-11-25 03:01:02
【问题描述】:
服务器和我的电脑都有 geckodriver 0.26.0、Firefox 71 和 Selenium 3.141.0。
我的电脑有 MacOS Mojave 和 python 3.8,服务器是 CentOS 7 和 python 3.7。该代码在我的计算机上完美运行,但它在服务器上返回错误。
我不记得怎么做了,但我得到了不同的错误,这取决于我是否向它添加断点,或者我是在终端中运行它还是在 SLURM 中提交作业。
在终端上:
File "Main.py", line 230, in <module>
main()
File "Main.py", line 179, in main
dfs=get_data(stations, inidate, findate)
File "Main.py", line 113, in get_data
list_files=return_list_day(date)
File "Main.py", line 66, in return_list_day
driver.get(webdir)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette
或
在 SLURM 上提交(并且最常见的错误):
Traceback (most recent call last):
File "Main.py", line 230, in <module>
main()
File "Main.py", line 179, in main
dfs=get_data(stations, inidate, findate)
File "Main.py", line 113, in get_data
list_files=return_list_day(date)
File "Main.py", line 66, in return_list_day
driver.get(webdir)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timeout loading page after 300000ms
我可以毫无问题地使用 Selenium 在另一个完成得很好的不相关代码中。所以我不明白为什么 Selenium 在这里或它是从哪里来的。
这里的代码失败了:
## Commented parts are cuz I tried running with the MOZ_HEADLESS tag on terminal
## Didnt make a difference as far as I could tell.
#options = Options()
#options.headless = True
driver = webdriver.Firefox()#options=options)
driver.get(webdir) ##<-- HERE
## Added these because of other replies to this issue I found
driver.implicitly_wait(7)
time.sleep(3)
.
.
.
driver.close()
那段代码从网页中检索一个列表,并在for-loop 中运行。错误不在检索部分,在driver.get(webdir)。我无法共享该网站,因为它实际上就像查看合作机构的服务器一样。 webdir 是一个目录,我基本上是在等待它的内容被加载,这样我才能检索它的文件名。
我知道如果没有网站,您将无能为力,但我所显示的错误是否能说明问题可能是什么?检索特定网站的行为是否会因操作系统而异?我用谷歌搜索了这些错误,在这里找到了问题,通读并应用它们以查看它是如何变化的,但什么也没发生,或者我得到了一个不同的错误(以上两个之一)。
我发现 this 表明 gecko 和 Mozilla 之间不兼容,但由于我可以成功运行另一个(不相关的)代码,准确调用和使用 Selenium(仅给出不同的 URL),所以我认为这不是我的问题.
感谢您的帮助!让我知道我可以提供哪些其他信息可能会有所帮助。
编辑:
这与链接的问题不同,因为我已经给它睡眠时间并且没有改变任何东西。它分配了 40 GB 的内存,因此它不会因为内存太少而死。 this question.中显示的解决方案有哪些
【问题讨论】:
-
RAM 应该不是问题,我为它分配了 40GB,因为在这部分之后,代码应该读取它找到的文件,然后可以将它们保存在本地(操作后)。添加它,因为据我所知,它解决了其他人的问题。
标签: python-3.x selenium selenium-webdriver