title: Python 3 POST request 400 error
body: <p>I'm trying to send request with urllib:</p>
  
  <pre><code>import urllib.request
  import urllib.parse
  from urllib.error import URLError, HTTPError
  
  api_key = ""
  base_url_string = 'URL'
  values = {'api_key' : api_key}
  
  user_agent = 'curl/7.47.0'
  headers = {'Content-Type' : 'application/json',
             'User-Agent': user_agent,
             'Accept' : '*/*'}
  
  data = urllib.parse.urlencode(values)
  data = data.encode('ascii')
  request = urllib.request.Request(url=base_url_string, data=data, headers=headers)
  
  try:
      response = urllib.request.urlopen(request)
      json_response = json.loads(response.read().decode("utf-8"))
  
      for line in json_response:
          print(line)
  
  except URLError as e:
      print(e)
  </code></pre>
  
  <p>and get "HTTP Error 400: Bad Request"</p>
  
  <pre><code>curl -v -H "Content-Type: application/json" -d '{"api_key":""}' URL
  </code></pre>
  
  <p>works fine.
  What am I missing here?</p>