title: Getting HTTP 400 Bad request while POST request using urllib
body: <p>Getting HTTP 400 bad request from testrail server when i try to post testcase result using urllib in python3. Appreciate if someone help me on this. Thanks!</p>
  
  <p>Below is code,</p>
  
  <pre><code>import urllib.request
  import json
  import base64
  
  data = {'results':[{'case_id': '123','status_id': '1','comment': 'This test passed', 'version': '0.14.0-W9'}]}
  headers = {}
  post_data = urllib.parse.urlencode(data).encode()
  auth = base64.b64encode(b'user:pass')
  auth = auth.decode()
  headers['Authorization'] = 'Basic %s' % auth
  headers['Content-Type'] = 'application/json'
  request = urllib.request.Request("http://testrail.com/index.php?/api/v2/add_results_for_cases/272374", data = post_data, headers = headers)
  response = urllib.request.urlopen(request).read()
  result = json.loads(response)
  print(result)
  </code></pre>
  
  <p>And error output,</p>
  
  <pre><code>Traceback (most recent call last):
    File "p3.py", line 13, in &lt;module&gt;
      response = urllib.request.urlopen(request).read()
    File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
      return opener.open(url, data, timeout)
    File "/usr/lib/python3.6/urllib/request.py", line 532, in open
      response = meth(req, response)
    File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
      'http', request, response, code, msg, hdrs)
    File "/usr/lib/python3.6/urllib/request.py", line 570, in error
      return self._call_chain(*args)
    File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
      result = func(*args)
    File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
      raise HTTPError(req.full_url, code, msg, hdrs, fp)
  urllib.error.HTTPError: HTTP Error 400: Bad Request
  </code></pre>