This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib2 post error when using httpproxy
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: jjlee, martin.panter, orsenthil, xhchen111
Priority: normal Keywords:

Created on 2005-03-10 01:37 by xhchen111, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg60697 - (view) Author: small tiger (xhchen111) Date: 2005-03-10 01:37
==============
program
==============
# -*- coding: gbk -*-
import httplib, urllib, urllib2#, cookielib

proxy = urllib2.ProxyHandler
({'http':'http://pic:iLusalt@proxy.pconline.com.cn:8080'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)

f = urllib2.urlopen
("http://192.168.10.177:8080/price/login.do?
method=list")
print f.read()

postdata = urllib.urlencode
({'userId':'admin', 'password':'admin'})
request = urllib2.Request
('http://192.168.10.177:8080/price/login.do?
method=login')
response = urllib2.urlopen(request, postdata)
print response.read()

====================
out put
====================
E:\jt>c:\python24\python t.py
Traceback (most recent call last):
  File "t.py", line 13, in ?
    response = urllib2.urlopen(request, postdata)
  File "c:\python24\lib\urllib2.py", line 130, in urlopen
    return _opener.open(url, data)
  File "c:\python24\lib\urllib2.py", line 358, in open
    response = self._open(req, data)
  File "c:\python24\lib\urllib2.py", line 376, in _open
    '_open', req)
  File "c:\python24\lib\urllib2.py", line 337, in _call_chain
    result = func(*args)
  File "c:\python24\lib\urllib2.py", line 1021, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "c:\python24\lib\urllib2.py", line 996, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error (10053, 'Software 
caused connection abort')>
msg60698 - (view) Author: John J Lee (jjlee) Date: 2006-05-28 00:15
Logged In: YES 
user_id=261020

The first URL hangs for me, using Firefox.  Especially if
this depends on using a proxy which I do not have permission
to use, I have no idea how to reproduce this.  xhchen111,
are you still around?
msg227775 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-09-28 20:57
From msg60698 "The first URL hangs for me, using Firefox.  Especially if
this depends on using a proxy which I do not have permission
to use, I have no idea how to reproduce this."  I certainly have no idea on how to reproduce this so unless someone can the only option I see is to close as "out of date".
msg341412 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2019-05-05 00:51
Today, proxy.pconline.com.cn resolves to a local (inaccessible) address for me (192.168.11.254). After changing the proxy address to localhost, and testing with Python 2.6.8, I can’t see any evidence of a bug in Python. Winsock error 10053 is WSAECONNABORTED, which apparently can be triggered after a lower-level protocol failure or timeout. So this could be the fault of the proxy, network, or a firewall. I am closing this, assuming nobody else can to reproduce this fifteen years later.

The closest I got is the following HTTP seen at the proxy:

>>> [conn, address] = listener.accept()
>>> pprint(conn.recv(3000).splitlines(keepends=True))
[b'GET http://192.168.10.177:8080/price/login.do?method=list HTTP/1.1\r\n',
 b'Accept-Encoding: identity\r\n',
 b'Host: 192.168.10.177:8080\r\n',
 b'Proxy-Authorization: Basic cGljOmlMdXNhbHQ=\r\n',
 b'Connection: close\r\n',
 b'User-Agent: Python-urllib/2.6\r\n',
 b'\r\n']
>>> conn.sendall(b'HTTP/1.1 200 Okay\r\nContent-Length: 0\r\n\r\n')
>>> conn.close()
>>> [conn, address] = listener.accept()
>>> pprint(conn.recv(3000).splitlines(keepends=True))
[b'POST http://192.168.10.177:8080/price/login.do?method=login HTTP/1.1\r\n',
 b'Accept-Encoding: identity\r\n',
 b'Content-Length: 27\r\n',
 b'Host: 192.168.10.177:8080\r\n',
 b'User-Agent: Python-urllib/2.6\r\n',
 b'Connection: close\r\n',
 b'Proxy-Authorization: Basic cGljOmlMdXNhbHQ=\r\n',
 b'Content-Type: application/x-www-form-urlencoded\r\n',
 b'\r\n',
 b'password=admin&userId=admin']

If I close the proxy’s listener before sending the first response, this causes ECONNREFUSED for the second request, with a similar back trace:

$ python2.6 t.py

Traceback (most recent call last):
  File "t.py", line 13, in <module>
    response = urllib2.urlopen(request, postdata)
  File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.6/urllib2.py", line 391, in open
    response = self._open(req, data)
  File "/usr/lib/python2.6/urllib2.py", line 409, in _open
    '_open', req)
  File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.6/urllib2.py", line 1181, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.6/urllib2.py", line 1156, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
History
Date User Action Args
2022-04-11 14:56:10adminsetgithub: 41676
2019-05-05 00:51:37martin.pantersetstatus: open -> closed

nosy: + martin.panter
messages: + msg341412

resolution: works for me
stage: test needed -> resolved
2019-04-26 20:36:40BreamoreBoysetnosy: - BreamoreBoy
2014-09-28 20:57:09BreamoreBoysetnosy: + BreamoreBoy

messages: + msg227775
versions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2
2010-08-21 12:36:55BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-02-12 17:40:26ajaksu2setnosy: + orsenthil
stage: test needed
type: behavior
versions: + Python 2.6, - Python 2.4
2005-03-10 01:37:13xhchen111create