Repository: youtube-dl
Issue: BBC iPlayer broken with python2, working with python3
Labels: geo-restricted

Downloading from BBC iPlayer errors out when using python2 but is fine when using python3

See log for details.

Not working with python2
```
[foo@bar Downloads]$ ./youtube-dl http://www.bbc.co.uk/iplayer/episode/b09ffxyn --proxy xxx.xxx.xx:80 --verbose 
[debug] System config: []
[debug] User config: [u'--no-part']
[debug] Custom config: []
[debug] Command-line args: [u'http://www.bbc.co.uk/iplayer/episode/b09ffxyn', u'--proxy', u'xxx.xxx.xx:80', u'--verbose']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2017.11.15
[debug] Python version 2.7.14 - Darwin-15.6.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.3.4, ffprobe 3.3.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Proxy map: {u'http': u'xxx.xxx.xx:80', u'https': u'xxx.xxx.xx:80'}
[bbc.co.uk] b09ffxyn: Downloading video page
[bbc.co.uk] b09ffxyn: Downloading playlist JSON
[bbc.co.uk] b09ffxss: Downloading media selection XML
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading MPD manifest
[bbc.co.uk] b09ffxss: Downloading MPD manifest
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
ERROR: An extractor error has occurred. (caused by KeyError('_Request__r_host',)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):
  File "./youtube-dl/youtube_dl/extractor/common.py", line 437, in extract
    ie_result = self._real_extract(url)
  File "./youtube-dl/youtube_dl/extractor/bbc.py", line 566, in _real_extract
    programme_id, title, description, duration, formats, subtitles = self._download_playlist(group_id)
  File "./youtube-dl/youtube_dl/extractor/bbc.py", line 462, in _download_playlist
    formats, subtitles = self._download_media_selector(programme_id)
  File "./youtube-dl/youtube_dl/extractor/bbc.py", line 327, in _download_media_selector
    mediaselector_url % programme_id, programme_id)
  File "./youtube-dl/youtube_dl/extractor/bbc.py", line 344, in _download_media_selector_url
    return self._process_media_selector(media_selection, programme_id)
  File "./youtube-dl/youtube_dl/extractor/bbc.py", line 391, in _process_media_selector
    m3u8_id=format_id, fatal=False)
  File "./youtube-dl/youtube_dl/extractor/common.py", line 1341, in _extract_m3u8_formats
    fatal=fatal)
  File "./youtube-dl/youtube_dl/extractor/common.py", line 535, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query)
  File "./youtube-dl/youtube_dl/extractor/common.py", line 506, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "./youtube-dl/youtube_dl/YoutubeDL.py", line 2196, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "./youtube-dl/youtube_dl/utils.py", line 1086, in https_open
    req, **kwargs)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1195, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 294, in get_selector
    return self.__r_host
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 253, in __getattr__
    return self.__dict__[attr]
KeyError: '_Request__r_host'
Traceback (most recent call last):
  File "./youtube-dl/youtube_dl/YoutubeDL.py", line 784, in extract_info
    ie_result = ie.extract(url)
  File "./youtube-dl/youtube_dl/extractor/common.py", line 450, in extract
    raise ExtractorError('An extractor error has occurred.', cause=e)
ExtractorError: An extractor error has occurred. (caused by KeyError('_Request__r_host',)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
```
Working with python3
```
[foo@bar Downloads]$ python3 ./youtube-dl http://www.bbc.co.uk/iplayer/episode/b09ffxyn --proxy xxx.xxx.xx:80 --verbose 
[debug] System config: []
[debug] User config: ['--no-part']
[debug] Custom config: []
[debug] Command-line args: ['http://www.bbc.co.uk/iplayer/episode/b09ffxyn', '--proxy', 'xxx.xxx.xx:80', '--verbose']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2017.11.15
[debug] Python version 3.5.1 - Darwin-15.6.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.3.4, ffprobe 3.3.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Proxy map: {'http': 'xxx.xxx.xx:80', 'https': 'xxx.xxx.xx:80'}
[bbc.co.uk] b09ffxyn: Downloading video page
[bbc.co.uk] b09ffxyn: Downloading playlist JSON
[bbc.co.uk] b09ffxss: Downloading media selection XML
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading MPD manifest
[bbc.co.uk] b09ffxss: Downloading MPD manifest
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading MPD manifest
[bbc.co.uk] b09ffxss: Downloading MPD manifest
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
WARNING: Failed to download m3u8 information: HTTP Error 403: Forbidden
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[bbc.co.uk] b09ffxss: Downloading m3u8 information
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on 'https://vod-dash-uk-live.bbcfmt.hs.llnwd.net/usp/auth/vod/piff_abr_full_hd/b6441d-b09ffxss/vf_b09ffxss_bbabecef-5811-4c75-a52b-b22066d95767.ism.hlsv2.ism/dash/'
[dashsegments] Total fragments: 440
[download] Destination: Detectorists, Series 3, Episode 2-b09ffxss.fstream-uk-iptv_streaming_concrete_combined_hd_mf_limelight_uk_dash_https-video=5070000.mp4
[download]   0.0% of ~630.53MiB at 90.40KiB/s ETA 20:04:24^C
ERROR: Interrupted by user
```