首页 > 解决方案 > Python ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))

问题描述

我已经寻找了很多关于这个问题的问题,但没有一个包含适合我的解决方案。这是我的代码:

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)

我试过 fake_useragent 但它没有用。许多解决方案表明使用标题可以解决问题,但对我不起作用。

标签: pythonweb-scraping

解决方案


有一个网站详细解释了如何通过 nba_api 获取 shotchartdetail 数据: https ://datavizardry.com/2020/01/28/nba-shot-charts-part-1/


推荐阅读