Python Requests Client Error: Bad Request, but works after website has been opened in browser
<p>I'm having a weird problem where I get a 400 Client Error: Bad Request on a url that I have never opened, but then if I open that same url with my browser and then close it, I am all of a sudden able to access it with Requests.</p>

<p>Here is my code:</p>

<pre><code>import requests
url = 'http://stats.nba.com/stats/boxscore?GameID=0021500669&amp;RangeType=0&amp;StartPeriod=0&amp;EndPeriod=0&amp;StartRange=0&amp;EndRange=0'
response = requests.get(url)
response.raise_for_status() # raise exception if invalid response
data = response.json()['resultSets'][0]['rowSet']
print data
</code></pre>

<p>If I run this before visiting the website on a browser I receive this error:</p>

<pre><code>Traceback (most recent call last):
File "stackOverflow.py", line 5, in &lt;module&gt;
response.raise_for_status() # raise exception if invalid response
File "C:\Python27\lib\site-packages\requests\models.py", line 851, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request
</code></pre>

<p>But after I visit the url in chrome and then run it again I get the list I was hoping for.</p>

<p>My first thought is that maybe the NBA is blocking some types of requests, could that be it?</p>

<p>Thanks for your help.</p>