Re: urllib2.urlopen error socket.error: [Errno 104] Connection reset by peer

2015-05-12 Thread dieter
Jia CHEN jia.j.c...@foxmail.com writes:

 I have the error below when trying to download the html content of a webpage. 
 I can open this webpage in a browser without any problem.

Connection reset by peer means that the other side (the HTTP server
in your case) has closed the connection.

It may have looked at the User-Agent request header to differentiate
between a browser request and an automated (script) request.

To work around this, you may provide a User-Agent header
to your urllib2.Request (see the documentation) letting
the User-Agent to look as if the request had been done by a browser
(Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
indicates a firefoy).

-- 
https://mail.python.org/mailman/listinfo/python-list


urllib2.urlopen error socket.error: [Errno 104] Connection reset by peer

2015-05-04 Thread Jia CHEN
Hi There,
 
I have the error below when trying to download the html content of a webpage. I 
can open this webpage in a browser without any problem. I am using Ubuntu 
14.04. Could you give me come clues about what is happening and how to solve 
the issue? Thanks.
 
$python 
 
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
 
[GCC 4.8.2] on linux2
 
Type help, copyright, credits or license for more information.
 
 import urllib2
 
request = 
urllib2.Request('http://guggenheiminvestments.com/products/etf/gsy/holdings')
 
response = urllib2.urlopen(request)
 
  Traceback (most recent call last):
 
File stdin, line 1, in module
 
File /usr/lib/python2.7/urllib2.py, line 127, in urlopen
 
return _opener.open(url, data, timeout)
 
File /usr/lib/python2.7/urllib2.py, line 404, in open
 
response = self._open(req, data)
 
File /usr/lib/python2.7/urllib2.py, line 422, in _open
 
'_open', req)
 
File /usr/lib/python2.7/urllib2.py, line 382, in _call_chain
 
result = func(*args)
 
File /usr/lib/python2.7/urllib2.py, line 1214, in http_open
 
return self.do_open(httplib.HTTPConnection, req)
 
File /usr/lib/python2.7/urllib2.py, line 1187, in do_open
 
r = h.getresponse(buffering=True)
 
File /usr/lib/python2.7/httplib.py, line 1045, in getresponse
 
response.begin()
 
File /usr/lib/python2.7/httplib.py, line 409, in begin
 
version, status, reason = self._read_status()
 
File /usr/lib/python2.7/httplib.py, line 365, in _read_status
 
line = self.fp.readline(_MAXLINE + 1)
 
File /usr/lib/python2.7/socket.py, line 476, in readline
 
data = self._sock.recv(self._rbufsize)
 
socket.error: [Errno 104] Connection reset by peer
 


Best,

Jia CHEN-- 
https://mail.python.org/mailman/listinfo/python-list