Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.error: [Errno 54] Connection reset by peer on very specific case #92

Open
jorgecarleitao opened this issue Feb 17, 2014 · 0 comments

Comments

@jorgecarleitao
Copy link

Using Python 2.7.6 and mechanize 0.2.5 in a virtualenv, try the following:
import mechanize
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) '
'AppleWebKit/537.36 (KHTML, like Gecko)')]
response = br.open("http://www.parlamento.pt/DeputadoGP/Paginas/Biografia.aspx?BID=2665")
print response.code
data = response.read()

on my machine (OS X 10.9.1), this is causing

 response.read()
 File ".../lib/python2.7/site-packages/mechanize/_response.py", line 190, in read
    self.__cache.write(self.wrapped.read())
 File ".../lib/python2.7/socket.py", line 351, in read
    data = self._sock.recv(rbufsize)
 File ".../lib/python2.7/httplib.py", line 567, in read
    s = self.fp.read(amt)
 File ".../lib/python2.7/socket.py", line 380, in read
    data = self._sock.recv(left)
 socket.error: [Errno 54] Connection reset by peer

This only happens in this particular url (i.e. ?BID=2665), and with those headers. Either other urls with same headers or no headers with same url cause no problem.

In my particular case I just removed headers, but it makes sense to keep this documented somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant