When the Sphinx Python API fails to connect to the Sphinx server, a
UnboundLocalError happens because a variable isn't correctly assigned... This
shouldn't happen at all..
_Connect() method:
try:
........
sock = socket.socket ( af, socket.SOCK_STREAM ) <--- this raises socket.error
sock.settimeout ( self._timeout )
sock.connect ( addr )
except socket.error, msg:
if sock: <--- sock doesn't exist!!! UnboundLocalError will be raised
sock.close()
self._error = 'connection to %s failed (%s)' % ( desc, msg )
return
Solution:
Just assign the sock variable first to None to make sure is exists.
Put
sock = None
before the try statement:
sock = None
try:
........
sock = socket.socket ( af, socket.SOCK_STREAM )
sock.settimeout ( self._timeout )
sock.connect ( addr )
except socket.error, msg:
if sock:
sock.close()
self._error = 'connection to %s failed (%s)' % ( desc, msg )
return
Original issue reported on code.google.com by pedrof.a...@gmail.com on 25 Oct 2013 at 11:04
Original issue reported on code.google.com by
pedrof.a...@gmail.com
on 25 Oct 2013 at 11:04