readline() takes exactly 1 argument (2 given)

I'm trying to make connections with proxies. and some of the times I get this error. I put the traceback below.

The command I use is this: `requests.get(w, verify=False, timeout=4, proxies=proxy)`
 `w` is a url and `proxy` is a dictionary.. something I make like this:

``` python
http_proxy  = "http://"+ip.strip()
https_proxy = http_proxy
proxyDict = { 
              "http"  : http_proxy, 
              "https" : https_proxy, 
            }
```

```
Traceback (most recent call last):
  File "explore_proxies.py", line 13, in onewebsite
    r= requests.get(w, verify=False, timeout=4, proxies=proxy)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 383, in req
uest
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 486, in sen
d
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 330, in sen
d
    timeout=timeout
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 537, i
n urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 299, i
n _get_conn
    return conn or self._new_conn()
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 719, i
n _new_conn
    return self._prepare_conn(connection)
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 686, i
n _prepare_conn
    connection.connect()
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 124, i
n connect
    self._tunnel()
  File "/usr/lib/python2.7/httplib.py", line 759, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)
```


What exact version of Python are you using? (e.g., 2.7.8)


Hi, thanks for raising this issue!

This is a known bug in the Python standard library, [issue 17849](http://bugs.python.org/issue17849). I have submitted a patch for this bug upstream, but it hasn't been merged at this time (despite being submitted in January). The best way to get this properly fixed is to try to agitate to get that patch merged.

We _may_ be able to fix this by doing #1869. @sigmavirus24, do you think it's worth it?


My only hesitation is @kennethreitz's previous resistance to the idea. Perhaps with the relatively recent release of the new version of HTTP/1.1 (which removes the necessity to support HTTP/0.9) he will be more willing.


I'm confident I could sell him on the idea. =)

> On 2 Aug 2014, at 10:35, Ian Cordasco notifications@github.com wrote:
> 
> My only hesitation is @kennethreitz's previous resistance to the idea. Perhaps with the relatively recent release of the new version of HTTP/1.1 (which removes the necessity to support HTTP/0.9) he will be more willing.
> 
> —
> Reply to this email directly or view it on GitHub.


This also stops pip>1.3.1 from proxying to pypi from a more local cheeseshop.


@bmcorser could you elaborate?


@bmcorser As discussed, this limitation is not in requests and there's really nothing we can do to speed things up. I recommend doing a code review of the patch I submitted to make it easier for the CPython maintainers to get it merged.


@Lukasa didn't we merge a PR that fixes this?


Yes. =)


Today when I was installing flask-mongoengine using pip, the same problem occured.
I executed 

``` bash
pip install flask-mongoengine
```

and returned 

``` bash
Downloading/unpacking flask-mongoengine
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 194, in find_requirement
    page = self._get_page(main_index_url, req)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 568, in _get_page
    session=self.session,
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 670, in get_page
    resp = session.get(url, headers={"Accept": "text/html"})
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 468, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 237, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 559, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 327, in send
    timeout=timeout
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 491, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 230, in _get_conn
    return conn or self._new_conn()
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 680, in _new_conn
    return self._prepare_conn(conn)
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 653, in _prepare_conn
    conn.connect()
  File "/usr/lib/python2.7/dist-packages/urllib3/connection.py", line 205, in connect
    self._tunnel()
  File "/usr/lib/python2.7/httplib.py", line 780, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)
```

My python version is 2.7.9, and my os is ubuntu14.10, does this bug still exist?


What version of pip are you using?


pip 1.5.6


That version of pip does not contain our fix, it's too old. Please upgrade. =)


I upgrade to pip 6.1.1 and the bug disappears. Thanks! :-)


Today when I was installing pb_tool using pip, the same problem occurred.
I executed

pip install pb_tool

and returned

Collecting pb-tool
Exception:
Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\basecommand.py", line 20
9, in main
    status = self.run(options, args)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\commands\install.py", li
ne 299, in run
    requirement_set.prepare_files(finder)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\req\req_set.py", line 36
0, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\req\req_set.py", line 51
2, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\req\req_install.py", lin
e 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\index.py", line 440, in
find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\index.py", line 398, in
find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\index.py", line 543, in
_get_pages
    page = self._get_page(location)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\index.py", line 646, in
_get_page
    return HTMLPage.get_page(link, session=self.session)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\index.py", line 755, in
get_page
    "Cache-Control": "max-age=600",
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\session
s.py", line 480, in get
    return self.request('GET', url, *_kwargs)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip\download.py", line 378,
in request
    return super(PipSession, self).request(method, url, *args, *_kwargs)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\session
s.py", line 468, in request
    resp = self.send(prep, *_send_kwargs)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\session
s.py", line 576, in send
    r = adapter.send(request, *_kwargs)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\cachecontrol\ada
pter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\adapter
s.py", line 376, in send
    timeout=timeout
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\package
s\urllib3\connectionpool.py", line 554, in urlopen
    self._prepare_proxy(conn)
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\package
s\urllib3\connectionpool.py", line 750, in _prepare_proxy
    conn.connect()
  File "C:\OSGEO4~1\apps\Python27\Lib\site-packages\pip_vendor\requests\package
s\urllib3\connection.py", line 230, in connect
    self._tunnel()
  File "C:\OSGEO4~1\apps\Python27\lib\httplib.py", line 759, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)

my python version is 2.7 and pip is 8.1.1.


What version of Python 2.7 please?


2.7.5


Ok, your error is likely the result of proxy configuration. Are you expecting to use a proxy? Because pip is trying to route through one, and that proxy is misbehaving quite badly. This was a known manifestation of a weird bug in CPython that was fixed [a year ago](https://bugs.python.org/issue17849), but was only triggered when a proxy was incorrectly configured.