title: Getting 400 bad request error while POSTing data with the requests module
body: <p>Title says everything, the strange part about it is GET requests and POST requests without data don't cause this error to occur. I'm presuming there's something wrong with the data I'm POSTing, not quite sure though. BTW, I'm using the cfscrape module (Re: <a href="https://github.com/Anorov/cloudflare-scrape" rel="nofollow">https://github.com/Anorov/cloudflare-scrape</a>) to bypass the Cloudflare DDoS protection loading page. Anyway, here's the code:</p>
  
  <pre><code>payload = { "username" : "testusername", "password" : "testpassword", "code" : "1111", "submit" : "Login" }
  scraper = cfscrape.create_scraper()
  res = scraper.post("http://www.umggaming.com/user/login", data=payload)
  print res.content
  </code></pre>
  
  <p>The reponse I get while POSTing data is </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;400 Bad Request&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;400 Bad Request&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;cloudflare-nginx&lt;/center&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>As previously mentioned, other requests i.e. GET requests and POST requests containing no data respond with the html source code successfully. I'm very confused as of right now. Hopefully someone can help me out. Thank you.</p>
  
  <p>@amow:</p>
  
  <pre><code>url = 'http://umggaming.com/user/login'
  values = { 'username' : 'testusername', 'password' : 'testpassword', 'code' : '1111', 'submit' : 'Login' }
  heads = { 
      'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)', 
      'Referer' : 'http://www.umggaming.com/user/login',
      'Cookie' : '__cfduid=EXAMPLE; cf_clearance=EXAMPLE'
  }
  data = urllib.urlencode(values)
  req = urllib2.Request(url, headers=heads, data=data)
  response = urllib2.urlopen(req)
  result = response.read()
  print result
  </code></pre>
  
  <p>EDIT: I was able to bypass Cloudflare with the above code, but I'm not getting the expected response when sending POST requests. If an invalid username/password/code pair in submitted, the page is supposed to respond with 'Sorry your password or code is incorrect.' - I'm not getting that response. Any ideas as to why this is happening?</p>