我有一个python脚本,可以从basketball-reference.com获取一些信息
它今天停止工作,由于这个错误:
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\util\ssl_.py", line 386, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\pphotsauce\anaconda3\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\pphotsauce\anaconda3\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\pphotsauce\anaconda3\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\adapters.py", line 439, in send
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\util\retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
MaxRetryError: HTTPSConnectionPool(host='www.basketball-reference.com', port=443): Max retries exceeded with url: /search/search.fcgi?search=RJ+Barrett (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "G:\fan_duel\april_version\main_2.py", line 13, in <module>
test = [f.get_bref_id_tester(x) for x in full_names]
File "G:\fan_duel\april_version\main_2.py", line 13, in <listcomp>
test = [f.get_bref_id_tester(x) for x in full_names]
File "G:\fan_duel\april_version\functions.py", line 30, in get_bref_id_tester
search_results_page = requests.get(url, headers=headers, allow_redirects='False')
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\api.py", line 76, in get
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\api.py", line 61, in request
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\sessions.py", line 542, in request
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\sessions.py", line 655, in send
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
SSLError: HTTPSConnectionPool(host='www.basketball-reference.com', port=443): Max retries exceeded with url: /search/search.fcgi?search=RJ+Barrett (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
runfile('G:/fan_duel/april_version/main_2.py', wdir='G:/fan_duel/april_version')
Reloaded modules: functions
Traceback (most recent call last):
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\util\ssl_.py", line 386, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\pphotsauce\anaconda3\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\pphotsauce\anaconda3\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\pphotsauce\anaconda3\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\adapters.py", line 439, in send
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\urllib3\util\retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
MaxRetryError: HTTPSConnectionPool(host='www.basketball-reference.com', port=443): Max retries exceeded with url: /search/search.fcgi?search=Chris+Boucher (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "G:\fan_duel\april_version\main_2.py", line 13, in <module>
test = [f.get_bref_id_tester(x) for x in full_names]
File "G:\fan_duel\april_version\main_2.py", line 13, in <listcomp>
test = [f.get_bref_id_tester(x) for x in full_names]
File "G:\fan_duel\april_version\functions.py", line 33, in get_bref_id_tester
search_results_page = requests.get(url, headers=headers, allow_redirects='False')
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\api.py", line 76, in get
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\api.py", line 61, in request
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\sessions.py", line 542, in request
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\sessions.py", line 655, in send
File "C:\Users\pphotsauce\anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
SSLError: HTTPSConnectionPool(host='www.basketball-reference.com', port=443): Max retries exceeded with url: /search/search.fcgi?search=Chris+Boucher (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
字符串
我有一个函数,它使用NBA球员的全名并返回篮球引用ID。如果我通过一个名称列表将此函数应用于Pandas系列或Pandas系列,则只有部分名称(每次不同的名称)会导致错误。('nightmare'是一个带有麻烦名称的字典)
nightmare = {
'Bol Bol': 'bolbo01',
'Nicolo Melli': 'mellini01',
'Davis Bertans': 'bertada01',
'Tomas Satoransky': 'satorto01',
'Theo Maledon': 'maledth01',
'Bogdan Bogdanovic': 'bogdabo01',
}
def get_bref_id(full_name):
sleep(0.2)
if full_name not in nightmare:
try:
first_name, last_name = full_name.split(' ')
url = 'https://www.basketball-reference.com/search/search.fcgi?search='+first_name+'+'+last_name
search_results_page = requests.get(url, allow_redirects = "False")
soup = bs(search_results_page.content, 'html.parser')
potential_links = soup.find_all('div', class_="search-item-name")
bucket = [element for element in potential_links if '202' in element.text if first_name in element.text]
bref_id = str(bucket[0]).replace('.', '/').split('/')[3]
except IndexError: # b-ref search occasionally takes you straight to the page
bref_id = search_results_page.url.split('/')[5].split('.')[0]
finally:
return bref_id
else:
return nightmare[full_name]
型
我不了解任何关于SSL或什么可能导致这个问题。如果你能指出我在正确的方向,了解更多,我将不胜感激。
3条答案
按热度按时间ki1q1bka1#
服务器
www.basketball-reference.com
至少需要TLS 1.2。看起来你的Python链接到了一个太旧的OpenSSL版本,不支持TLS 1.2。使用下面的代码检查使用的是哪个OpenSSL版本。对TLS 1.2的支持是很久以前OpenSSL 1.0.1添加的,但是例如MacOS很长一段时间都是使用旧版本OpenSSL 0.9.8。字符串
gojuced72#
也有类似的问题。
这是
requests
库的一个bug。我通过在处理程序字典中将
https
替换为http
来修复https协议。例如:如果代理是https,则像这样声明(代理IP中不带S:
"https": "http://10.10.1.10:1080"
个范例:
字符串
7cjasjjr3#
尝试在headers参数中添加用户代理。此外,我添加了一个输入选项,如果搜索返回多个选项,您可以选择:
产品代码:
字符串
输出:
型