请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,这个报错怎么解决啊

#coding=utf-8
import json
import requests
url = 'http://127.0.0.1:4444/wd/hub/session/'
data = json.dumps({
‘desiredCapabilities’:{
‘browserName’:‘chrome’
}
})
res = requests.post(url, data).json()
session = res[‘sessionId’]
print(session)

控制台报错:
D:\练习python\seleniumpythonbase\venv\Scripts\python.exe D:/练习python/seleniumpythonbase/ThreeNode/requests_open_browser.py
Traceback (most recent call last):
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connection.py”, line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\util\connection.py”, line 96, in create_connection
raise err
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\util\connection.py”, line 86, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connectionpool.py”, line 706, in urlopen
chunked=chunked,
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connectionpool.py”, line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connection.py”, line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File “D:\Python\Python36\lib\http\client.py”, line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File “D:\Python\Python36\lib\http\client.py”, line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “D:\Python\Python36\lib\http\client.py”, line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “D:\Python\Python36\lib\http\client.py”, line 1026, in _send_output
self.send(msg)
File “D:\Python\Python36\lib\http\client.py”, line 964, in send
self.connect()
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connection.py”, line 200, in connect
conn = self._new_conn()
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connection.py”, line 182, in _new_conn
self, “Failed to establish a new connection: %s” % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001DCF9545198>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\requests\adapters.py”, line 449, in send
timeout=timeout
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\connectionpool.py”, line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\urllib3\util\retry.py”, line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=4444): Max retries exceeded with url: /wd/hub/session/ (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x000001DCF9545198>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。’,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:/练习python/seleniumpythonbase/ThreeNode/requests_open_browser.py”, line 10, in
res = requests.post(url, data).json()
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\requests\api.py”, line 119, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\requests\api.py”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\requests\sessions.py”, line 542, in request
resp = self.send(prep, **send_kwargs)
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\requests\sessions.py”, line 655, in send
r = adapter.send(request, **kwargs)
File “D:\练习python\seleniumpythonbase\venv\lib\site-packages\requests\adapters.py”, line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘127.0.0.1’, port=4444): Max retries exceeded with url: /wd/hub/session/ (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x000001DCF9545198>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。’,))

Process finished with exit code 1

正在回答 回答被采纳积分+3

1回答

Mushishi 2021-01-14 22:42:27

你selenium server stand online有没有启动啊

0 回复 有任何疑惑可以回复我~
  • 提问者 慕粉1212355798 #1
    没有启动,老师我用这个 url = 'https://www.imooc.com/'  可以吗,如果启动selenium server stand online这个它的jar包应该放在哪里
    cmd报错:
    C:\Users\nj>java -jar selenium-server-standalone-3.9.1.jar -port 4444 -role hub
    Error: Unable to access jarfile selenium-server-standalone-3.9.1.jar
    回复 有任何疑惑可以回复我~ 2021-01-15 16:01:13
  • Mushishi 回复 提问者 慕粉1212355798 #2
    你哦那个上面url无所谓。但是你一定要保证你cmd到你的selenium server 这个jar所在目录之后再去执行这个命令啊。你看我怎么操作的  启动之后再访问
    回复 有任何疑惑可以回复我~ 2021-01-15 22:52:20
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信