TypeError:urlopen()在Kubuntu 14.04上通过Selenium和Python执行测试时获得了关键字参数“body”的多个值

2024-03-28 22:24:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在Kubuntu 14.04上运行python中的selenium。 我尝试chromedriver或geckodriver时得到这个错误消息,两者都是相同的错误。

Traceback (most recent call last):
  File "vse.py", line 15, in <module>
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'/root/Desktop/chromedriver')
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py", line 375, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.4/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/python3/dist-packages/urllib3/request.py", line 79, in request
    **urlopen_kw)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 142, in request_encode_body
    **urlopen_kw)
TypeError: urlopen() got multiple values for keyword argument 'body'

import time
import mapeamentos as map
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from random import randint
import datetime
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'/root/Desktop/chromedriver')
driver.get('http://192.168.1.11:66/webclient/login.html')

在以下位置触发此错误:

driver = webdriver.Chrome()

我试过有选择,没有选择,没有硬编码的路径。

我不知道发生了什么事。谢谢大家。


Tags: infrompyimportremoterequestlibpackages
2条回答

您可以使用

pip install --upgrade --ignore-installed urllib3

此错误消息。。。

TypeError: urlopen() got multiple values for keyword argument 'body'

…意味着在内部调用urlopen()时,Python客户机遇到错误。

此错误通常是由系统包管理器安装的pip旧版本引起的,可以用较新版本的pip替换。


解决方案

升级到最新版本(至少v18.0)将解决您的问题。

C:\Users\myUser>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.3MB 544kB/s
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0

参考文献

相关问题 更多 >