title: Pycurl and io.StringIO - pycurl.error: (23, 'Failed writing body)
body: <p>I'm porting ebay sdk to python3 and I've stumbled upon the following issue.</p>
  
  <p>I'm using pycurl to send some HTTP requests.
  Here is how I configure it:</p>
  
  <pre><code>    self._curl = pycurl.Curl()
      self._curl.setopt(pycurl.FOLLOWLOCATION, 1)
      self._curl.setopt(pycurl.URL, str(request_url))
      self._curl.setopt(pycurl.SSL_VERIFYPEER, 0)
  
      self._response_header = io.StringIO()
      self._response_body = io.StringIO()
  
      self._curl.setopt(pycurl.CONNECTTIMEOUT, self.timeout)
      self._curl.setopt(pycurl.TIMEOUT, self.timeout)
  
      self._curl.setopt(pycurl.HEADERFUNCTION, self._response_header.write)
      self._curl.setopt(pycurl.WRITEFUNCTION, self._response_body.write)
  </code></pre>
  
  <p>When I call self._curl.perform() I get the following error:</p>
  
  <pre><code>pycurl.error: (23, 'Failed writing body (1457 != 1460)')
  </code></pre>
  
  <p>As far as I know this means that there is an issue with the write function, but I can't figure out what it is exactly. Could be related to migration from StringIO module to io, but I'm not sure.</p>
  
  <p><strong>UPD</strong>:
  I've tried the following: </p>
  
  <pre><code>    def body(buf):
          self._response_body.write(buf)
  
      def header(buf):
          self._response_header.write(buf)
  
      self._curl.setopt(pycurl.HEADERFUNCTION, header)
      self._curl.setopt(pycurl.WRITEFUNCTION, body)
  </code></pre>
  
  <p>and it works. I've tried to do the same trick with lambdas (instead of defining those awkward function, but it didn't work.</p>