Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5262 defect closed duplicate (duplicate)

twisted.web.client.HTTPClient breaks on bare LF-terminated header fields

Reported by: jacky ma Owned by:
Priority: normal Milestone:
Component: web Keywords:
Cc: jknight, ivank Branch:
Author:

Description (last modified by Jean-Paul Calderone)

my english is poor,please look at following:

        Traceback (most recent call last):
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 84, in callWithLogger
            return callWithContext({"system": lp}, func, *args, **kw)
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 69, in callWithContext
            return context.call({ILogContext: newCtx}, func, *args, **kw)
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 118, in callWithContext
            return self.currentContext().callWithContext(ctx, func, *args, **kw)
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 81, in callWithContext
            return func(*args,**kw)
        --- <exception caught here> ---
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
            why = getattr(selectable, method)()
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
            rval = self.protocol.dataReceived(data)
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/protocols/basic.py", line 564, in dataReceived
            why = self.lineReceived(line)
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/web/http.py", line 448, in lineReceived
            self.extractHeader(self._header)
          File "/usr/local/python2.7/lib/python2.7/site-packages/Twisted-11.0.0-py2.7-linux-x86_64.egg/twisted/web/http.py", line 409, in extractHeader
            self.length = int(val)
        exceptions.ValueError: invalid literal for int() with base 10: '831\nPragma: no-cache'

Change History (3)

comment:1 Changed 6 years ago by DefaultCC Plugin

Cc: jknight added

comment:2 Changed 6 years ago by ivank

Cc: ivank added
Milestone: Python-2.7
Resolution: duplicate
Status: newclosed
Summary: exceptions.ValueError: invalid literal for int() with base 10: '831\nPragma: no-cache'twisted.web.client.HTTPClient breaks on bare LF-terminated header fields

You're getting a response from a broken server that sends \n instead of the correct line terminator \r\n. If you use the new HTTP client twisted.web.client.Agent [1] in a recent version of Twisted, it'll be able to handle an HTTP response that uses n.

[1] http://twistedmatrix.com/documents/10.1.0/web/howto/client.html#auto2

This is a duplicate of #2842

comment:3 Changed 6 years ago by Jean-Paul Calderone

Description: modified (diff)

Fixing description markup, too.

Note: See TracTickets for help on using tickets.