私は専用サーバーで Ubuntu Xenial 16.04 を実行しており、Python でコーディングを始めたいと思ったので、次のチュートリアルに従いました。https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-programming-environment-on-an-ubuntu-16-04-server
Selenium と Chromedriver もインストールし、次のような非常にシンプルな script.py を作成しました。
from time import sleep
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.google.com')
sleep(5)
browser.close()
しかし、スクリプトを実行すると、永久にハングアップしてしまい、中断せざるを得なくなります。そうすると、次のようになります。
^CTraceback (most recent call last):
File "script.py", line 4, in <module>
browser = webdriver.Chrome()
File "/home/vcluzeau/python/my_env/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/home/vcluzeau/python/my_env/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/home/vcluzeau/python/my_env/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/vcluzeau/python/my_env/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 310, in execute
response = self.command_executor.execute(driver_command, params)
File "/home/vcluzeau/python/my_env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 466, in execute
return self._request(command_info[0], url, body=data)
File "/home/vcluzeau/python/my_env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 490, in _request
resp = self._conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
これをどう修正すればよいかご存知ですか? ありがとうございます!
答え1
Python エラーの蒸気ローラーパッケージからPython ソフトウェア動的コンパイル、抽象構文ツリーの書き換え、ライブ コール スタックの変更、そしてプログラミングを困難にする厄介なエラーをすべて取り除くための愛情を組み合わせて使用します。これは、エラーを引き起こすモジュールに対する即時の一時的な解決策です。