Catch socket.error

Also pep8 formatting