简体   繁体   English

Python ConnectionError: ('Connection aborted.', OSError(“(10060, 'WSAETIMEDOUT')”))

[英]Python ConnectionError: ('Connection aborted.', OSError(“(10060, 'WSAETIMEDOUT')”))

I have looked for lots of questions on this issue but none of them contains a solution that works for me yet.我已经寻找了很多关于这个问题的问题,但没有一个包含适合我的解决方案。 Here is my code:这是我的代码:

import requests
import pandas as pd
shot_chart_url = 'https://stats.nba.com/stats/shotchartdetail?AheadBehind=&CFID=&CFPARAMS=&ClutchTime=&Conference=&ContextFilter=&ContextMeasure=FGM&DateFrom=&DateTo=&Division=&EndPeriod=10&EndRange=28800&GROUP_ID=&GameEventID=&GameID=&GameSegment=&GroupID=&GroupMode=&GroupQuantity=5&LastNGames=0&LeagueID=00&Location=&Month=0&OnOff=&OpponentTeamID=0&Outcome=&PORound=0&Period=0&PlayerID={PlayerID}&PlayerID1=&PlayerID2=&PlayerID3=&PlayerID4=&PlayerID5=&PlayerPosition=&PointDiff=&Position=&RangeType=0&RookieYear=&Season={Season}&SeasonSegment=&SeasonType={SeasonType}&ShotClockRange=&StartPeriod=1&StartRange=0&StarterBench=&TeamID=0&VsConference=&VsDivision=&VsPlayerID1=&VsPlayerID2=&VsPlayerID3=&VsPlayerID4=&VsPlayerID5=&VsTeamID='\
                  .format(PlayerID=201935, Season='2019-20', SeasonType='Regular+Season')

headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
response = requests.get(shot_chart_url, headers=headers)
headers = response.json()['resultSets'][0]['headers']
shots = response.json()['resultSets'][0]['rowSet']
shot_df = pd.DataFrame(shots, columns=headers)

I had tried fake_useragent but it didn't work.我试过 fake_useragent 但它没有用。 Lots of solutions indicates that using the headers could fix the problem but doesn't work for me.许多解决方案表明使用标题可以解决问题,但对我不起作用。

There is a website that explains the detail of how to get shotchartdetail data by nba_api: https://datavizardry.com/2020/01/28/nba-shot-charts-part-1/有一个网站详细解释了如何通过 nba_api 获取 shotchartdetail 数据: https://datavizardry.com/2020/01/28/nba-shot-charts-part-1/

from nba_api.stats.endpoints import shotchartdetail
import json

response = shotchartdetail.ShotChartDetail(
    team_id=0,
    player_id=201935,
    season_nullable='2019-20',
    season_type_all_star='Regular Season'
)

content = json.loads(response.get_json())

Output: Output:

{"resource": "shotchartdetail", "parameters": {"LeagueID": "00", "Season": "2019-20", "SeasonType": "Regular Season", "TeamID": 0, "PlayerID": 201935, "GameID": null, "Outcome": null, "Location": null, "Month": 0, "SeasonSegment": null, "DateFrom": null, "DateTo": null, "OpponentTeamID": 0, "VsConference": null, "VsDivision": null, "Position": null, "RookieYear": null, "GameSegment": null, "Period": 0, "LastNGames": 0, "ClutchTime": null, "AheadBehind": null, "PointDiff": null, "RangeType": null, "StartPeriod": null, "EndPeriod": null, "StartRange": null, "EndRange": null, "ContextFilter": "", "ContextMeasure": "PTS"}, "resultSets": [{"name": "Shot_Chart_Detail", "headers": ["GRID_TYPE", "GAME_ID", "GAME_EVENT_ID", "PLAYER_ID", "PLAYER_NAME", "TEAM_ID", "TEAM_NAME", "PERIOD", "MINUTES_REMAINING", "SECONDS_REMAINING", "EVENT_TYPE", "ACTION_TYPE", "SHOT_TYPE", "SHOT_ZONE_BASIC", "SHOT_ZONE_AREA", "SHOT_ZONE_RANGE", "SHOT_DISTANCE", "LOC_X", "LOC_Y", "SHOT_ATTEMPTED_FLAG", "SHOT_MADE_FLAG", "GAME_DATE", "HTM", "VTM"], "rowSet": [["Shot Chart Detail", "0021900015", 350, 201935, "James Harden", 1610612745, "Houston Rockets", 2, 2, 6, "Made Shot", "Driving Layup Shot", "2PT Field Goal", "Restricted Area", "Center(C)", "Less Than 8 ft.", 3, 22, 21, 1, 1, "20191024", "HOU", "MIL"], ["Shot Chart Detail", "0021900015", 353, 201935, "James Harden", 1610612745, "Houston Rockets", 2, 1, 40, "Made Shot", "Step Back Jump shot", "3PT Field Goal", "Above the Break 3", "Center(C)", "24+ ft.", 28, -43, 278, 1, 1, "20191024", "HOU", "MIL"], ["Shot Chart Detail", "0021900032", 8, 201935, "James Harden", 1610612745, "Houston Rockets", 1, 11, 38, "Made Shot", "Driving Layup Shot", "2PT Field Goal", "Restricted Area", "Center(C)", "Less Than 8 ft.", 1, -14, 7, 1, 1, "20191026", "HOU", "NOP"], ["Shot Chart Detail", "0021900032", 115, 201935, "James Harden",
....
....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 网络抓取错误('连接中止',OSError(“(10060,'WSAETIMEDOUT')”)) - Python Webscraping Error ('Connection aborted.', OSError(“(10060, 'WSAETIMEDOUT')”)) 请求超时错误 (requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))) - Requests Timeout Error (requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))) Python Spider ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Spider ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) Web 抓取 - 请求 ConnectionError: ('Connection aborted.', OSError(“(60, 'ETIMEDOUT')”,)) - Web Scraping - Requests ConnectionError: ('Connection aborted.', OSError(“(60, 'ETIMEDOUT')”,)) Python: requests.exceptions.ConnectionError: ('Connection aborted.', OSError(“(54, 'ECONNRESET')”,)) - Python: requests.exceptions.ConnectionError: ('Connection aborted.', OSError(“(54, 'ECONNRESET')”,)) Python-requests [('连接中止。', TimeoutError(10060) ] - Python-requests [('Connection aborted.', TimeoutError(10060) ] python - requests.get(连接中止。',OSError(“(60,'ETIMEDOUT') - python - requests.get (Connection aborted.', OSError("(60, 'ETIMEDOUT') 使用 python 请求获取 ('Connection aborted.', OSError(0, 'Error') 错误 - Getting ('Connection aborted.', OSError(0, 'Error') errors with python requests 如何在 Python 中跳过“Connection aborted.”、OSError(0, 'Error')? - How can I skip 'Connection aborted.', OSError(0, 'Error') in Python? 当xml大小增加时,Python请求XML API异常ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Requests XML API Exception ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) when xml size increases
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM