aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-11-24 06:37:14 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-11-24 06:39:10 +0100
commit13ebea791fb4293acf939730ad5a9c07e553005f (patch)
tree41c80457fadece9c091c3080ee9d20166db57ca6 /youtube_dl/utils.py
parent4c9c57428f2b5bbafb56912a861703754e78e545 (diff)
[niconico] Simplify and make work with old Python versions
The website requires SSLv3, otherwise it just times out during SSL negotiation.
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 0720fe9eb..34b3d19e0 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -12,6 +12,7 @@ import os
import pipes
import platform
import re
+import ssl
import socket
import sys
import traceback
@@ -535,13 +536,31 @@ def formatSeconds(secs):
else:
return '%d' % secs
+
def make_HTTPS_handler(opts):
- if sys.version_info < (3,2):
- # Python's 2.x handler is very simplistic
- return compat_urllib_request.HTTPSHandler()
+ if sys.version_info < (3, 2):
+ import httplib
+
+ class HTTPSConnectionV3(httplib.HTTPSConnection):
+ def __init__(self, *args, **kwargs):
+ httplib.HTTPSConnection.__init__(self, *args, **kwargs)
+
+ def connect(self):
+ sock = socket.create_connection((self.host, self.port), self.timeout)
+ if self._tunnel_host:
+ self.sock = sock
+ self._tunnel()
+ try:
+ self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_SSLv3)
+ except ssl.SSLError as e:
+ self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_SSLv23)
+
+ class HTTPSHandlerV3(compat_urllib_request.HTTPSHandler):
+ def https_open(self, req):
+ return self.do_open(HTTPSConnectionV3, req)
+ return HTTPSHandlerV3()
else:
- import ssl
- context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ context = ssl.SSLContext(ssl.PROTOCOL_SSLv3)
context.set_default_verify_paths()
context.verify_mode = (ssl.CERT_NONE