title: How to POST chunked encoded data in Python
body: <p>I am trying to POST chunked encoded data to httpbin.org/post. I tried two options: Requests and httplib</p>
  
  <h1>Using Requests</h1>
  
  <pre><code>#!/usr/bin/env python
  
  import requests
  
  def gen():
          l = range(130)
          for i in l:
                  yield '%d' % i
  
  if __name__ == "__main__":
          url = 'http://httpbin.org/post'
          headers = {
                          'Transfer-encoding':'chunked',
                          'Cache-Control': 'no-cache',
                          'Connection': 'Keep-Alive',
                          #'User-Agent': 'ExpressionEncoder'
                  }
          r = requests.post(url, headers = headers, data = gen())
          print r
  </code></pre>
  
  <h1>Using httplib</h1>
  
  <pre><code>#!/usr/bin/env python
  
  import httplib
  import os.path
  
  if __name__ == "__main__":
          conn = httplib.HTTPConnection('httpbin.org')
          conn.connect()
          conn.putrequest('POST', '/post')
          conn.putheader('Transfer-Encoding', 'chunked')
          conn.putheader('Connection', 'Keep-Alive')
          conn.putheader('Cache-Control', 'no-cache')
          conn.endheaders()
          for i in range(130):
                  conn.send(str(i))
  
          r = conn.getresponse()
          print r.status, r.reason
  </code></pre>
  
  <p>In both of these cases, whenever I analyze Wireshark traces, I do not see multiple chunks being sent. Instead, what I see is that all of the data is being sent in a single chunk? Am I missing something here?</p>