gpt4 book ai didi

python - 使用 python 请求获取 ('Connection aborted.' 、 OSError(0, 'Error' ) 错误

转载 作者:行者123 更新时间:2023-12-03 07:36:49 33 4
gpt4 key购买 nike

我正在尝试编写代码以登录网站。
首先我使用 ARC 进行测试.它工作正常。 Image

所以我写了这样的python代码:

import requests


url = 'https://www.bible.ac.kr/login.aspx/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko',
'Referer': 'http://www.bible.ac.kr/'
}


req = requests.get(url, headers=headers) # OR requests.get(url, headers=headers, verify=False)

print(req.status_code)

但我有错误。

错误
Traceback (most recent call last):
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
conn.connect()
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
ssl_context=context)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/util/retry.py", line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
conn.connect()
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
ssl_context=context)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(0, 'Error'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/kyungmin/PycharmProjects/untitled14/a.py", line 11, in <module>
req = requests.get(url, headers=headers)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

Process finished with exit code 1


我很久没有解决这个问题了。
只有当我运行 Fiddler ,代码工作正常。我不知道原因。
即使我尝试使用 C 语言,我仍然在这个网站上遇到错误。
你能只用 Python 解决这个问题吗?

最佳答案

我使用 OPENSSL 1.0.1f 解决了这个问题.
该域仅支持 TLS 1.0、SSLv2 和 SSLv3。这些协议(protocol)已经过时并且很少使用。所以我怀疑 OPENSSL 1.1.1 的兼容性系列。结果,使用 openssl 版本 1.0.1f解决了这个问题。但是,在 Python 中使用较旧的 openssl 可能需要额外的工作。
我的英语不是很好,但我希望这会有所帮助。

关于python - 使用 python 请求获取 ('Connection aborted.' 、 OSError(0, 'Error' ) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57672038/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com