# Buggy code
def __init__(self, code=None, msg=None):
    if code is not None and msg is None:
        msg = self.CODES.get(code) and "unknown error"
    super(ProxyError, self).__init__(code, msg)


# Traceback (youtube_dl.socks.Socks5Error)
$ youtube-dl -v --proxy socks5://127.0.0.1:9050/ http://www.spiegel.tv/filme/bbc-gefaehrliche-strassen-sibirien/
[debug] System config: []
[debug] User config: [u'--restrict-filenames', u'--no-mtime', u'--no-part', u'-x', u'-k', u'--audio-format', u'mp3', u'--audio-quality', u'0']
[debug] Command-line args: [u'-v', u'--proxy', u'socks5://127.0.0.1:9050/', u'http://www.spiegel.tv/filme/bbc-gefaehrliche-strassen-sibirien/']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2016.12.01
[debug] Python version 2.7.12 - Linux-4.1.34-33-default-x86_64-with-SuSE-42.1-x86_64
[debug] exe versions: ffmpeg 3.0.2, ffprobe 3.0.2, rtmpdump 2.4
[debug] Proxy map: {u'http': u'socks5://127.0.0.1:9050/', u'https': u'socks5://127.0.0.1:9050/'}
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Downloading webpage
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Downloading version information
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Downloading object information
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Downloading media information
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Downloading server information
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Checking hls video format URL
[Spiegeltv] bbc-gefaehrliche-strassen-sibirien: Checking hls video format URL
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/bin/youtube-dl/__main__.py", line 19, in <module>
File "/usr/bin/youtube-dl/youtube_dl/__init__.py", line 444, in main

File "/usr/bin/youtube-dl/youtube_dl/__init__.py", line 434, in _real_main

File "/usr/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1791, in download
File "/usr/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 694, in extract_info
File "/usr/bin/youtube-dl/youtube_dl/extractor/common.py", line 357, in extract
File "/usr/bin/youtube-dl/youtube_dl/extractor/spiegeltv.py", line 94, in _real_extract
File "/usr/bin/youtube-dl/youtube_dl/extractor/common.py", line 1004, in _check_formats
File "/usr/bin/youtube-dl/youtube_dl/extractor/common.py", line 1003, in <lambda>
File "/usr/bin/youtube-dl/youtube_dl/extractor/common.py", line 1022, in _is_valid_url
File "/usr/bin/youtube-dl/youtube_dl/extractor/common.py", line 404, in _request_webpage
File "/usr/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 2001, in urlopen
File "/usr/lib64/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/usr/lib64/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/usr/lib64/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/bin/youtube-dl/youtube_dl/utils.py", line 872, in http_open
File "/usr/lib64/python2.7/urllib2.py", line 1195, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib64/python2.7/httplib.py", line 1057, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.7/httplib.py", line 1097, in _send_request
self.endheaders(body)
File "/usr/lib64/python2.7/httplib.py", line 1053, in endheaders
self._send_output(message_body)
File "/usr/lib64/python2.7/httplib.py", line 897, in _send_output
self.send(msg)
File "/usr/lib64/python2.7/httplib.py", line 859, in send
self.connect()
File "/usr/bin/youtube-dl/youtube_dl/utils.py", line 1002, in connect
File "/usr/bin/youtube-dl/youtube_dl/socks.py", line 269, in connect
def __negotiatesocks4(self,destaddr,destport):
File "/usr/bin/youtube-dl/youtube_dl/socks.py", line 265, in _make_proxy
machine (note: getproxypeername returns the proxy)
File "/usr/bin/youtube-dl/youtube_dl/socks.py", line 240, in _setup_socks5
else:
youtube_dl.socks.Socks5Error: [Errno 4] unknown error

# Fixed code
def __init__(self, code=None, msg=None):
    if code is not None and msg is None:
        msg = self.CODES.get(code) or "unknown error"
    super(ProxyError, self).__init__(code, msg)