Repository: ytdl-org/youtube-dl

Issue:
ERROR: readline() takes exactly 1 argument (2 given)
I get this error message ONLY WHEN http_proxy variable is set.

[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'--verbose', u'-ciw', u'-f', u'bestaudio', u'--write-all-thumbnails', u'--no-mtime', u'--download-archive', u'.archive.txt', u'--playlist-start', u'1', u'https://www.youtube.com/watch?v=tVAI3voBG1E&list=RDtVAI3voBG1E']
[debug] Encodings: locale UTF-8, fs UTF-8, out None, pref UTF-8
[debug] youtube-dl version 2015.08.28
[debug] Python version 2.7.10 - CYGWIN_NT-6.1-WOW-2.2.0-0.289-5-3-i686-32bit
[debug] exe versions: ffmpeg N-72346-ga838b22, ffprobe N-72346-ga838b22
[debug] Proxy map: {'http': '78.188.251.242:8080', u'https': '78.188.251.242:8080'}
[youtube:playlist] Downloading playlist RDtVAI3voBG1E - add --no-playlist to just download video tVAI3voBG1E
[youtube:playlist] RDtVAI3voBG1E: Downloading Youtube mix
ERROR: readline() takes exactly 1 argument (2 given)
Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 655, in extract_info
    ie_result = ie.extract(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 287, in extract
    return self._real_extract(url)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 1572, in _real_extract
    return self._extract_mix(playlist_id)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py", line 1485, in _extract_mix
    url, playlist_id, 'Downloading Youtube mix')
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 438, in _download_webpage
    res = self._download_webpage_handle(url_or_request, video_id, note, errnote, fatal, encoding=encoding)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 345, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal)
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 326, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1860, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(_args)
  File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 749, in https_open
    req, *_kwargs)
  File "/usr/lib/python2.7/urllib2.py", line 1194, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/usr/lib/python2.7/httplib.py", line 1053, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1093, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 1049, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 893, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 855, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 1266, in connect
    HTTPConnection.connect(self)
  File "/usr/lib/python2.7/httplib.py", line 835, in connect
    self._tunnel()
  File "/usr/lib/python2.7/httplib.py", line 819, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)



Discussion:
Python 2.7.10

It works fine for me, that line of code is executed without problem. Could you try [with an official cpython build](https://www.python.org/downloads/release/python-2710/)?

I tried with latest python python-2.7.10.msi (md5sum 4ba2c79b103f6003bc4611c837a08208).
Started from CMD with windows python.
Same error:

[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'-ciw', u'-f', u'bestaudio', u'--write-all-thumbnails', u'--no-mtime', u'--download-archive', u'.archive.txt', u'--playlist-start', u'1', u'-a', u'alink.txt', u'--verbose']
[debug] Batch file urls: [u'https://www.youtube.com/watch?v=tVAI3voBG1E&list=RDtVAI3voBG1E']
[debug] Encodings: locale cp1252, fs mbcs, out cp437, pref cp1252
[debug] youtube-dl version 2015.08.28
[debug] Python version 2.7.10 - Windows-7-6.1.7601-SP1
[debug] exe versions: ffmpeg N-72346-ga838b22, ffprobe N-72346-ga838b22
[debug] Proxy map: {'http': '223.19.230.181:80', u'https': '223.19.230.181:80'}
[youtube:playlist] Downloading playlist RDtVAI3voBG1E - add --no-playlist to just download video tVAI3voBG1E
[youtube:playlist] RDtVAI3voBG1E: Downloading Youtube mix
ERROR: readline() takes exactly 1 argument (2 given)
Traceback (most recent call last):
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\YoutubeDL.py", line 655, in extract_info
    ie_result = ie.extract(url)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\extractor\common.py", line 287, in extract
    return self._real_extract(url)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\extractor\youtube.py", line 1572, in _real_extract
    return self._extract_mix(playlist_id)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\extractor\youtube.py", line 1485, in _extract_mix
    url, playlist_id, 'Downloading Youtube mix')
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\extractor\common.py", line 438, in _download_webpage
    res = self._download_webpage_handle(url_or_request, video_id, note, errnote, fatal, encoding=encoding)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\extractor\common.py", line 345, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\extractor\common.py", line 326, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\YoutubeDL.py", line 1860, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "C:\Python27\lib\urllib2.py", line 431, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 449, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
    result = func(_args)
  File "c:\cygwin\usr\local\bin\youtube-dl\youtube_dl\utils.py", line 749, in https_open
    req, *_kwargs)
  File "C:\Python27\lib\urllib2.py", line 1194, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "C:\Python27\lib\httplib.py", line 1053, in request
    self._send_request(method, url, body, headers)
  File "C:\Python27\lib\httplib.py", line 1093, in _send_request
    self.endheaders(body)
  File "C:\Python27\lib\httplib.py", line 1049, in endheaders
    self._send_output(message_body)
  File "C:\Python27\lib\httplib.py", line 893, in _send_output
    self.send(msg)
  File "C:\Python27\lib\httplib.py", line 855, in send
    self.connect()
  File "C:\Python27\lib\httplib.py", line 1266, in connect
    HTTPConnection.connect(self)
  File "C:\Python27\lib\httplib.py", line 835, in connect
    self._tunnel()
  File "C:\Python27\lib\httplib.py", line 819, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)

I can reproduce this as well. It's a [python issue](http://bugs.python.org/issue17849).


Resolving patch:
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -587,6 +587,11 @@ def __init__(self, downloaded, expected):
 
 
 def _create_http_connection(ydl_handler, http_class, is_https, *args, **kwargs):
+    # Working around python 2 bug (see http://bugs.python.org/issue17849) by limiting
+    # expected HTTP responses to meet HTTP/1.0 or later (see also
+    # https://github.com/rg3/youtube-dl/issues/6727)
+    if sys.version_info < (3, 0):
+        kwargs['strict'] = True
     hc = http_class(*args, **kwargs)
     source_address = ydl_handler._params.get('source_address')
     if source_address is not None:


Test patch: