Окружающая среда
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
НКУ
gcc --version
gcc (Ubuntu 4.8.5-4ubuntu8~14.04.2) 4.8.5
Python
python --version
Python 2.7.6
Pip
pip --version
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
urllib3
pip list | grep url
urllib3 1.7.1
Chromedriver
chromedriver --version
ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4)
Хром
chromium-browser --version
Chromium 65.0.3325.181 Built on Ubuntu , running on Ubuntu 14.04
Селен
pip install selenium
Requirement already satisfied: selenium in /usr/local/lib/python2.7/dist-packages (3.141.0)
Requirement already satisfied: urllib3 in /usr/lib/python2.7/dist-packages (from selenium) (1.7.1)
Драйвер Chrome для Linux 64bit
Я пробовал несколько версий, но все приводят к одной и той же новой проблеме
rm ~/Downloads/chromedriver_linux64.zip \
wget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip -P ~/Downloads; \
unzip ~/Downloads/chromedriver_linux64.zip -d ~/Downloads; \
chmod +x ~/Downloads/chromedriver; \
rm /usr/local/share/chromedriver; \
sudo mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver; \
rm /usr/local/bin/chromedriver; \
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver; \
rm /usr/bin/chromedriver; \
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver; \
ls -al /usr/bin/chromedriver; \
ls -al /usr/local/bin/chromedriver; \
ls -al /usr/local/share/chromedriver
... попробовал
# wget -N http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip -P ~/Downloads
# wget -N http://chromedriver.storage.googleapis.com/2.27/chromedriver_linux64.zip -P ~/Downloads
# wget -N http://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip -P ~/Downloads
# wget -N http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip -P ~/Downloads
# wget -N http://chromedriver.storage.googleapis.com/71.0.3578.33/chromedriver_linux64.zip -P ~/Downloads
Тестовый скрипт test.py
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=d)
# load some site
driver.get('http://foo.com')
# print messages
for entry in driver.get_log('browser'):
print entry
Error
python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
driver = webdriver.Chrome(desired_capabilities=d)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "/usr/lib/python2.7/dist-packages/urllib3/request.py", line 79, in request
**urlopen_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/request.py", line 142, in request_encode_body
**urlopen_kw)
TypeError: urlopen() got multiple values for keyword argument 'body'
Подписан на другие темы
TypeError: urlopen получил несколько значений для ключевого аргумента 'body' при выполнении тестов через Selenium и Python на Kubuntu 14.04
urllib3 версия
# aptitude show python-urllib3
Package: python-urllib3
State: installed
Automatically installed: yes
Version: 1.7.1-1ubuntu4.1
Priority: optional
Section: python
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Uncompressed Size: 201 k
Depends: python:any (< 2.8), python:any (>= 2.7.5-5~), python-six
Recommends: ca-certificates
Description: HTTP library with thread-safe connection pooling for Python
urllib3 supports features left out of urllib and urllib2 libraries.
* Re-use the same socket connection for multiple requests (HTTPConnectionPool and HTTPSConnectionPool) (with optional client-side certificate verification).
* File posting (encode_multipart_formdata).
* Built-in redirection and retries (optional).
* Supports gzip and deflate decoding.
* Thread-safe and sanity-safe.
* Small and easy to understand codebase perfect for extending and building upon.
Homepage: http://urllib3.readthedocs.org
У меня есть другая установка с теми же версиями хром-драйвера хром-браузера, и ошибка не возникает. Что еще я мог проверить?
Есть еще указатели?
UPDATE
В среде, где проблема не возникает, версия pip не совпадает.
pip v1.5.4
вместо pip install --upgrade pip==1.5.4
Теперь удалите pip 18.1
и переустановите мои pip-пакеты.
Чтобы установить обратно последнюю версию pip
, если вы хотите вернуться снова
python -m pip install --upgrade pip
Также отметил, что на работающей машине у меня немного другая версия GCC
gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Решено
Мне пришлось начать со свежей установки Xubuntu и запустить
sudo pip install -U urllib3