[Baypiggies] Need help root causing exception http.client.BadStatusLine

AM ams.fwd at gmail.com
Mon Oct 29 06:34:25 CET 2012


This is specific to python httplib, so using FF against nc wouldnt help. 
Keep in mind that what we are trying to do here is to simulate the 
behaviour of the tomcat server so that the python client raises a 
BadStatusLine error. Which means that netcat is the server and the 
client is the python code.

So in the second nc that you pasted here, try ctrl-c-ing it before 
typing out the response just like you did with the first one and let us 
know what the python traceback says.

AM

On 10/28/2012 10:22 PM, Shubhra Sharma wrote:
> nc -l -p 8080 doesnot work on my osx.
> ssharma-dev1:newscripts ssharma$ nc -l localhost 8080
> GET /xyz/api/states/syncingIds HTTP/1.1
> Host: localhost:8080
> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) 
> Gecko/20100101 Firefox/16.0
> Accept: */*
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> X-Requested-With: XMLHttpRequest
> Referer: http://localhost:8080/xyz/
>
> ^C
> ssharma-dev1:newscripts ssharma$ nc -l localhost 8080
> POST /ucx/api/nodes/ HTTP/1.1
> Host: localhost:8080
> Content-Length: 78
> accept-encoding: gzip, deflate
> content-type: application/json; charset=UTF-8
> accept: application/json
> user-agent: Python-httplib2/0.7.6 (gzip)
>
> {"parentId":1275,"name":"COMPANY-2012-10-28 
> 19:57:24.507300","type":"COMPANY"}^C
>
>
>
> On Sun, Oct 28, 2012 at 10:16 PM, AM <ams.fwd at gmail.com 
> <mailto:ams.fwd at gmail.com>> wrote:
>
>     Strange. On debian testing with python 2.7 with the following
>     steps I get this output:
>
>     1. Start netcat, (note: OSX does now allow -p with -l)
>     2. Fire the request
>     3. ctrl-c netcat
>
>     Can you reproduce that?
>
>     netcat:
>     » nc -l -p 8080
>     GET /hello HTTP/1.1
>     Accept-Encoding: identity
>     Host: localhost:8080
>     Connection: close
>     User-Agent: Python-urllib/2.7
>
>     ^C
>
>
>     Interpreter:
>     » python
>     Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
>     [GCC 4.6.3] on linux2
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> from urllib2 import urlopen
>     >>> r = urlopen('http://localhost:8080/hello')
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>       File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
>         return _opener.open(url, data, timeout)
>       File "/usr/lib/python2.7/urllib2.py", line 400, in open
>         response = self._open(req, data)
>       File "/usr/lib/python2.7/urllib2.py", line 418, in _open
>         '_open', req)
>       File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
>         result = func(*args)
>       File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open
>         return self.do_open(httplib.HTTPConnection, req)
>       File "/usr/lib/python2.7/urllib2.py", line 1180, in do_open
>         r = h.getresponse(buffering=True)
>       File "/usr/lib/python2.7/httplib.py", line 1030, in getresponse
>         response.begin()
>       File "/usr/lib/python2.7/httplib.py", line 407, in begin
>
>         version, status, reason = self._read_status()
>       File "/usr/lib/python2.7/httplib.py", line 371, in _read_status
>         raise BadStatusLine(line)
>     httplib.BadStatusLine: ''
>
>     >>>
>
>
>     On 10/28/2012 08:17 PM, Shubhra Sharma wrote:
>
>         So nc -l localhost 8080 in one terminal tab and running my
>         client in another tab. My client does several POST, PUT and
>         some GETs. I did a Ctrl-C but didnot hit the Bad StatusLine on
>         my OSX10.7.x. I never hit the Bad StatusLine on my OSX10.7.x.
>         It occurs only on CentOS. Maybe I am missing something?
>
>         Thanks for your help,
>         Shubhra
>
>         On Sun, Oct 28, 2012 at 7:09 PM, AM <ams.fwd at gmail.com
>         <mailto:ams.fwd at gmail.com> <mailto:ams.fwd at gmail.com
>         <mailto:ams.fwd at gmail.com>>> wrote:
>
>             I think what Guido meant was that the server was alive but
>         did not
>             respond with anything, instead closing the connection.
>
>             Assuming you are running on linux or OSX a quick way to
>         check it
>             is to use the netcat tool in a terminal:
>
>             nc -l -p 8080
>
>             Then have your client connect to localhost:8080/...
>
>             In the terminal you should see the request. Ctrl-C netcat
>         and you
>             should (afaik) see the BadStatusLine error.
>
>             What that would mean is that somewhere tomcat decided to
>         simply
>             close the connection before any response was sent out.
>
>             HTH
>             AM
>
>
>             On 10/28/2012 06:37 PM, Shubhra Sharma wrote:
>
>                 Hi Guido,
>
>                 Thanks for responding.I will check the catalina logs
>         to see
>                 what happened.
>
>                 When tomcat is not running on my setup I see the
>         following error:
>
>                   File
>                
>         "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/httplib2/__init__.py",
>                 line 1207, in request
>                     (response, content) = self._request(conn,
>         authority, uri,
>                 request_uri, method, body, headers, redirections,
>         cachekey)
>                   File
>                
>         "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/httplib2/__init__.py",
>                 line 961, in _request
>                     (response, content) = self._conn_request(conn,
>                 request_uri, method, body, headers)
>                   File
>                
>         "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/httplib2/__init__.py",
>                 line 898, in _conn_request
>                     conn.connect()
>                   File
>                
>         "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/http/client.py",
>                 line 724, in connect
>                     self.timeout, self.source_address)
>                   File
>                
>         "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/socket.py",
>                 line 404, in create_connection
>                     raise err
>                   File
>                
>         "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/socket.py",
>                 line 395, in create_connection
>                     sock.connect(sa)
>                 socket.error: [Errno 61] Connection refused
>
>                 I did not see the BadStatusLine exception in my
>         unittesting.
>                 Is there anything I can do to catch this exception,
>         the try
>                 catch around the http request did not catch it? I am using
>                 httplib2 if that helps
>                 Thanks,
>                 Shubhra
>
>                 On Sun, Oct 28, 2012 at 5:28 PM, Guido van Rossum
>                 <guido at python.org <mailto:guido at python.org>
>         <mailto:guido at python.org <mailto:guido at python.org>>
>                 <mailto:guido at python.org <mailto:guido at python.org>
>         <mailto:guido at python.org <mailto:guido at python.org>>>> wrote:
>
>                     That particular line where this is raised means
>         the server
>                 closed the
>                     connection without sending any response at all.
>         Check your
>                 server
>                     logs?
>
>                     On Sun, Oct 28, 2012 at 4:00 PM, Shubhra Sharma
>                     <sharma.shubhra07 at gmail.com
>         <mailto:sharma.shubhra07 at gmail.com>
>                 <mailto:sharma.shubhra07 at gmail.com
>         <mailto:sharma.shubhra07 at gmail.com>>
>                 <mailto:sharma.shubhra07 at gmail.com
>         <mailto:sharma.shubhra07 at gmail.com>
>
>                 <mailto:sharma.shubhra07 at gmail.com
>         <mailto:sharma.shubhra07 at gmail.com>>>>
>
>                     wrote:
>                     > Hi Aahz,
>                     >
>                     > Thanks for responding. I'm not sending an Expect
>         Header
>                 and I'm
>                     using
>                     > Apache-Coyote/1.1
>                     >
>                     > Thanks,
>                     > Shubhra
>                     >
>                     >
>                     > On Sun, Oct 28, 2012 at 2:06 PM, Aahz
>                 <aahz at pythoncraft.com <mailto:aahz at pythoncraft.com>
>         <mailto:aahz at pythoncraft.com <mailto:aahz at pythoncraft.com>>
>                     <mailto:aahz at pythoncraft.com
>         <mailto:aahz at pythoncraft.com>
>
>                 <mailto:aahz at pythoncraft.com
>         <mailto:aahz at pythoncraft.com>>>> wrote:
>                     >>
>                     >> On Sun, Oct 28, 2012, Shubhra Sharma wrote:
>                     >> >
>                     >> > I am encountering http.client.BadStatusLine
>         exception
>                 when I
>                     run my
>                     >> > python
>                     >> > scripts on CentOS6.32 but things seem to work
>         fine on MAC
>                     OSX10.7.5 and
>                     >> > 10.8. I'm on Python3.2.3.
>                     >> >
>                     >> > I searched for answers on the internet  and
>         looked at
>                 the python
>                     >> > documentation as well without much luck. As
>         per the
>                     documentation  if a
>                     >> > server responds with a HTTP status code that
>         we don?t
>                     understand this
>                     >> > error
>                     >> > is raised. The server is a Tomcat server. Any
>         ideas
>                 on how to
>                     debug this
>                     >> > will be greatly appreciated.
>                     >> >
>                     >> > Here's a snippet of the error:
>                     >> > response = conn.getresponse()
>                     >> >   python3.2/http/client.py", line 1049, in
>         getresponse
>                     >> >     response.begin()
>                     >> >   python3.2/http/client.py", line 346, in begin
>                     >> >     version, status, reason = self._read_status()
>                     >> >   python3.2/http/client.py", line 328, in
>         _read_status
>                     >> >     raise BadStatusLine(line)
>                     >> > http.client.BadStatusLine:
>                     >>
>                     >> I've seen various causes for this, but I'd start by
>                 making sure
>                     that
>                     >> you're not sending an Expect: header and doing
>         HTTP/1.0
>                 connection.
>                     >> --
>                     >> Aahz (aahz at pythoncraft.com
>         <mailto:aahz at pythoncraft.com>
>                 <mailto:aahz at pythoncraft.com
>         <mailto:aahz at pythoncraft.com>> <mailto:aahz at pythoncraft.com
>         <mailto:aahz at pythoncraft.com>
>
>                 <mailto:aahz at pythoncraft.com
>         <mailto:aahz at pythoncraft.com>>>)              <*>
>
>                     >> http://www.pythoncraft.com/
>                     >>
>                     >> "We've just found a line in a perl script that
>         invokes
>                 a shell
>                     script to
>                     >> call
>                     >> a lisp program which invokes the very-same perl
>         script."
>                      --anonymous
>                     >> _______________________________________________
>                     >> Baypiggies mailing list
>                     >> Baypiggies at python.org
>         <mailto:Baypiggies at python.org> <mailto:Baypiggies at python.org
>         <mailto:Baypiggies at python.org>>
>                 <mailto:Baypiggies at python.org
>         <mailto:Baypiggies at python.org> <mailto:Baypiggies at python.org
>         <mailto:Baypiggies at python.org>>>
>
>
>                     >> To change your subscription options or unsubscribe:
>                     >> http://mail.python.org/mailman/listinfo/baypiggies
>                     >
>                     >
>                     >
>                     > _______________________________________________
>                     > Baypiggies mailing list
>                     > Baypiggies at python.org
>         <mailto:Baypiggies at python.org> <mailto:Baypiggies at python.org
>         <mailto:Baypiggies at python.org>>
>                 <mailto:Baypiggies at python.org
>         <mailto:Baypiggies at python.org> <mailto:Baypiggies at python.org
>         <mailto:Baypiggies at python.org>>>
>
>
>                     > To change your subscription options or unsubscribe:
>                     > http://mail.python.org/mailman/listinfo/baypiggies
>
>
>
>                     --
>                     --Guido van Rossum (python.org/~guido
>         <http://python.org/%7Eguido>
>                 <http://python.org/%7Eguido> <http://python.org/%7Eguido>)
>
>
>
>
>
>                 _______________________________________________
>                 Baypiggies mailing list
>
>         Baypiggies at python.org <mailto:Baypiggies at python.org>
>         <mailto:Baypiggies at python.org <mailto:Baypiggies at python.org>>
>                 To change your subscription options or unsubscribe:
>         http://mail.python.org/mailman/listinfo/baypiggies
>
>
>
>
>



More information about the Baypiggies mailing list