Resetting state of http.client/httplib HTTPSConnection objects

2013-08-26 Thread Chris Down
This is a crosspost from python-tutor upon suggestion.

I am experiencing intermittent issues where an exception will be raised when
calling getresponse(), which makes the entire connection stuck in Request-sent
state. Is it possible to reset to idle state somehow without reinstantiating
the HTTPSConnection? I ideally want to keep the connection to the server, and
just reset the state to idle so that I can make another request (like you would
usually do by calling getresponse()).

 a.conn
http.client.HTTPSConnection object at 0x7f8d7cb58bd0
 a.conn.getresponse()
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib64/python3.3/http/client.py, line 1143, in getresponse
response.begin()
  File /usr/lib64/python3.3/http/client.py, line 354, in begin
version, status, reason = self._read_status()
  File /usr/lib64/python3.3/http/client.py, line 324, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''
 a.conn.request(GET, foo)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib64/python3.3/http/client.py, line 1061, in request
self._send_request(method, url, body, headers)
  File /usr/lib64/python3.3/http/client.py, line 1089, in _send_request
self.putrequest(method, url, **skips)
  File /usr/lib64/python3.3/http/client.py, line 944, in putrequest
raise CannotSendRequest(self.__state)
http.client.CannotSendRequest: Request-sent


pgpkTDZASsW7A.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lxml tostring quoting too much

2013-08-06 Thread Chris Down
On 2013-08-06 18:38, andrea crotti wrote:
 I would really like to do the following:

 from lxml import etree as ET
 from lxml.builder import E

 url = http://something?x=10y=20;
 l = E.link(url)
 ET.tostring(l) - linkhttp://something?x=10y=20/link

 However the lxml tostring always quotes the , I can't find a way to
 tell it to avoid quoting it.

You're probably aware, but without the escaping, it is no longer well formed
XML. Why do you want to do that? Is there a larger underlying problem that
should be solved instead?

Either way, you can use unescape from the xml.sax.saxutils module[0].

Chris

0: http://docs.python.org/2/library/xml.sax.utils.html


pgp5LbtvsyYqj.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner question

2013-08-06 Thread Chris Down
On 2013-08-06 14:35, eschneide...@comcast.net wrote:
 Why won't the 'goodbye' part of this code work right? it prints 'ok' no
 matter what is typed. Much thanks.

if statements do not fall through, because the first statement was matched,
no other ones in the same chain will be evaluted.

elif means else if, where else means if nothing previous matched.


pgpmktmYIQJiC.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list