mamaduckmaster / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

py3k: HTTPConnectionWithTimeout.connect fails to raise socket.error if an exception occurred #122

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I've run into the following traceback in Python 3.1:

Traceback (most recent call last):
  File "E:\prg\py\App\hgmgr2\src\httplib2\__init__.py", line 851, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "C:\Python31\lib\http\client.py", line 918, in request
    self._send_request(method, url, body, headers)
  File "C:\Python31\lib\http\client.py", line 956, in _send_request
    self.endheaders(body)
  File "C:\Python31\lib\http\client.py", line 914, in endheaders
    self._send_output(message_body)
  File "C:\Python31\lib\http\client.py", line 768, in _send_output
    self.send(msg)
  File "C:\Python31\lib\http\client.py", line 716, in send
    self.connect()
  File "E:\prg\py\App\hgmgr2\src\httplib2\__init__.py", line 740, in connect
    raise socket.error(msg)
UnboundLocalError: local variable 'msg' referenced before assignment

I've tracked this down to a change in the scope of the local variable of 
handled exception. The small example below works with Python 2.5 but fails with 
Python 3.1:

---
def main():
    msg = 'a message'
    try:
        raise ValueError( 'An error' )
    except ValueError as msg:
        pass
    return msg

main()

---

The attached patch fix this issue by introducing another local variable that is 
assigned to in the exception handler.

Original issue reported on code.google.com by baptiste...@gmail.com on 31 Dec 2010 at 8:09

Attachments:

GoogleCodeExporter commented 8 years ago
Ooops. This is a duplicate of 
http://code.google.com/p/httplib2/issues/detail?id=79 which contains a better 
patch for this bug.

Original comment by baptiste...@gmail.com on 31 Dec 2010 at 8:16

GoogleCodeExporter commented 8 years ago

Original comment by joe.gregorio@gmail.com on 13 Feb 2011 at 5:02