Python response.get()要么不';不要返回或超时

Python response.get()要么不';不要返回或超时,python,python-3.x,python-requests,response,urllib,Python,Python 3.x,Python Requests,Response,Urllib,我试图运行以下代码片段从指定的url检索数据。我尝试使用'timeout=5'参数,并将其忽略 最终的结果是运行脚本要么挂起python,要么我得到一条超时错误消息?在浏览器中打开url似乎会返回有效的json,但我似乎无法在python中提取数据 怎么回事 import requests url = "http://stats.nba.com/stats/shotchartdetail?Period=0&VsConference=&LeagueID=00&LastNG

我试图运行以下代码片段从指定的url检索数据。我尝试使用'timeout=5'参数,并将其忽略

最终的结果是运行脚本要么挂起python,要么我得到一条超时错误消息?在浏览器中打开url似乎会返回有效的json,但我似乎无法在python中提取数据

怎么回事

import requests

url = "http://stats.nba.com/stats/shotchartdetail?Period=0&VsConference=&LeagueID=00&LastNGames=0&TeamID=0&Position=&Location=&Outcome=&ContextMeasure=FGA&DateFrom=&StartPeriod=&DateTo=&OpponentTeamID=0&ContextFilter=&RangeType=&Season=2016-17&AheadBehind=&PlayerID=202738&EndRange=&VsDivision=&PointDiff=&RookieYear=&GameSegment=&Month=0&ClutchTime=&StartRange=&EndPeriod=&SeasonType=Regular+Season&SeasonSegment=&GameID=&PlayerPosition="

response = requests.get(url,timeout=5)
print(response)

您没有传递头,特别是在头中传递用户代理

用户代理请求标头包含一个特征字符串,该字符串允许网络协议对等方识别请求软件用户代理的应用程序类型、操作系统、软件供应商或软件版本


您没有传递头,特别是在头中传递用户代理

用户代理请求标头包含一个特征字符串,该字符串允许网络协议对等方识别请求软件用户代理的应用程序类型、操作系统、软件供应商或软件版本

headers ={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.78 Chrome/60.0.3112.78 Safari/537.36"}

response = requests.get(url,headers=headers,timeout=5)
print response.text