类型错误:在 Xubuntu 14.04.5 上尝试 Selenium 时,urlopen() 为关键字参数“body"获得了多个值 [英] TypeError: urlopen() got multiple values for keyword argument 'body' while trying Selenium on Xubuntu 14.04.5

查看:93
本文介绍了类型错误:在 Xubuntu 14.04.5 上尝试 Selenium 时,urlopen() 为关键字参数“body"获得了多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# 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 --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     

Chrome 驱动程序

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)

Linux 64 位 Chrome 驱动程序安装

我尝试了多个版本,但都导致相同的问题

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

错误

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 got multiple在 Kubuntu 14.04 上通过 Selenium 和 Python 执行测试时关键字参数body"的值

# 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

我有另一个具有相同铬浏览器 chromedriver 版本的设置,但没有发生错误.我还能检查什么?

I have another setup with same chromium-browser chromedriver versions and the error doesn't happen. What else could I check?

还有什么建议吗?

在没有发生问题的环境中,pip 版本不一样.

On the environment where the issue doesn't happen the pip version isn't the same.

pip v1.5.4 代替 pip install --upgrade pip==1.5.4现在卸载 pip 18.1 并重新安装我的 pip 包.

pip v1.5.4 instead pip install --upgrade pip==1.5.4 Now uninstalling pip 18.1 and reinstalling my pip packages.

如果您想再次恢复,请安装回最新版本的pip

To install back the latest version of pip if you want to revert again

python -m pip install --upgrade pip

还注意到,在正常运行的机器上,我的 GCC 版本略有不同

Also noted that on the functioning machine I have a slightly different version of GCC

gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

已解决

我必须从全新的 Xubuntu 设置开始并运行

Resolved

I had to start from a fresh Xubuntu setup and ran

sudo pip install -U urllib3

推荐答案

潜在的解决方案:

1- 尝试升级 urllib3 版本,根据:https://github.com/kubernetes-client/python/blob/master/requirements.txt

1- Try upgrading the version o urllib3, seems like the version of urllib3 is old according to: https://github.com/kubernetes-client/python/blob/master/requirements.txt

确保 urllib3 的版本为 1.16 或更高.在这里,您可以找到设置:https://launchpad.net/ubuntu/+source/python-urllib3/1.21.1-1

Make sure the version of urllib3 is 1.16 or more. Here, you can find the setup: https://launchpad.net/ubuntu/+source/python-urllib3/1.21.1-1

Ref(SO 中的另一篇文章):TypeError: urlopen() 在 Kubuntu 14.04 上通过 Selenium 和 Python 执行测试时,为关键字参数body"获取了多个值

Ref (another post in SO): TypeError: urlopen() got multiple values for keyword argument 'body' while executing tests through Selenium and Python on Kubuntu 14.04

2-更新python版本:

2- Update the version of python:

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update 
sudo apt-get install python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
sudo update-alternatives --config python3

参考:http://ubuntuhandbook.org/index.php/2017/07/install-python-3-6-1-in-ubuntu-16-04-lts/

这篇关于类型错误:在 Xubuntu 14.04.5 上尝试 Selenium 时,urlopen() 为关键字参数“body"获得了多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆