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: Open url with proxy causes TypeError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Missing size argument in readline() method for httplib's class LineAndFileWrapper
View: 17849
Assigned To: Nosy List: orsenthil, r.david.murray, zhang.kai
Priority: normal Keywords:

Created on 2012-09-12 05:44 by zhang.kai, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg170354 - (view) Author: zhang kai (zhang.kai) Date: 2012-09-12 05:44
Here is the code which causes this bug:
 proxy_handler = urllib2.ProxyHandler({'https': proxy})
 opener = urllib2.build_opener(proxy_handler)
 f = opener.open(url+'?'+params)

Here are the traceback information:
Traceback (most recent call last):
  File "proxy.py", line 65, in <module>
    main()
  File "proxy.py", line 62, in main
    print proxy_manager.get_proxy()
  File "proxy.py", line 45, in get_proxy
    make_request(TEST_URL, proxy=one["proxy_server"])
  File "proxy.py", line 27, in make_request
    f = opener.open(url+'?'+params)
  File "/usr/lib/python2.7/urllib2.py", line 400, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 418, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1215, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1174, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/usr/lib/python2.7/httplib.py", line 958, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 992, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 776, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 1160, in connect
    self._tunnel()
  File "/usr/lib/python2.7/httplib.py", line 748, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)
msg170355 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-09-12 06:13
Have a look at the ProxyHandler example in the Examples here - http://docs.python.org/library/urllib2.html#examples
Also, construct the full url properly with urlencoded data as params.

Your report does not give any details of problem.
msg170356 - (view) Author: zhang kai (zhang.kai) Date: 2012-09-12 06:24
Well, I do have encoded the params, that is not the problem.
Also these code did work for most of the time, I don't know why this bug happen so I don't know any details about the problem. Sorry about that.
msg170362 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-09-12 10:15
What is proxy?  Perhaps it does not implement readline correctly.
History
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 60132
2015-05-31 03:32:17martin.pantersetsuperseder: Missing size argument in readline() method for httplib's class LineAndFileWrapper
resolution: not a bug -> duplicate
2012-09-12 10:15:23r.david.murraysetnosy: + r.david.murray
messages: + msg170362
2012-09-12 06:24:57zhang.kaisetmessages: + msg170356
2012-09-12 06:14:11orsenthilsetstatus: open -> closed
2012-09-12 06:13:39orsenthilsetnosy: + orsenthil
messages: + msg170355

resolution: not a bug
stage: resolved
2012-09-12 05:44:41zhang.kaicreate