When I run this code in iPython (Python 2.7):
from requests import get
_get = get('http://stats.nba.com/stats/playergamelog', params={'PlayerID': 203083, 'Season':'2015-16', 'SeasonType':'Regular Season'})
print _get.url
_get.raise_for_status()
_get.json()
I am getting:
http://stats.nba.com/stats/playergamelog?PlayerID=203083&Season=2015-16&SeasonType=Regular+Season
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-5-8f8343b2c4cd> in <module>()
1 _get = get('http://stats.nba.com/stats/playergamelog', params={'PlayerID': 203083, 'Season':'2015-16', 'SeasonType':'Regular Season'})
2 print _get.url
----> 3 _get.raise_for_status()
4 _get.json()
/Library/Python/2.7/site-packages/requests/models.pyc in raise_for_status(self)
849
850 if http_error_msg:
--> 851 raise HTTPError(http_error_msg, response=self)
852
853 def close(self):
HTTPError: 400 Client Error: Bad Request
However, if I go to the url in my browser, it works. Then, when I come back to the code and run it again after manually visiting the URL in my browser (Chrome which iPython is running in), the code runs with no error. However, it may go back to raising the error in sequential executions.
This code has worked for me hundreds if not thousands of times with no issue. How do I fix this error?
Thanks.