python-3.x - 如何修复 Python 中的 urlopen 错误?使用 youtube-dl

标签 python-3.x ssl pyopenssl youtube-dl

如何处理这个错误:

我无法在 MacO 上解决这个问题!没有人可以帮助我吗?在 Windows 上运行良好!

@菲哈格

youtube-dl -U :

Updating to version 2017.11.15 ... 

openssl 版本 -a:

OpenSSL 1.0.2m  2 Nov 2017
built on: reproducible build, date unspecified
platform: darwin64-x86_64-cc
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: clang -I. -I.. -I../include  -fPIC -fno-common -DOPENSSL_PIC -DZLIB_SHARED -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/local/etc/openssl"



python --version:

Python 2.7.14

python3 --version:

Python 3.6.3 

youtube-dl 命令:

youtube-dl -v -u myEmail@gmail.com -p myPassword -o '~/Development/tutorials/new/%(playlist)s/%(chapter_number)s - %(chapter)s/%(title)s.%(ext)s'  https://www.udemy.com/react-the-complete-guide-incl-redux/learn/v4/content 

终端输出:

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'-u', u'PRIVATE', u'-p', u'PRIVATE', u'-o', u'~/Development/tutorials/new/%(playlist)s/%(chapter_number)s - %(chapter)s/%(title)s.%(ext)s', u'https://www.udemy.com/react-the-complete-guide-incl-redux/learn/v4/content']
[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-16.7.0-x86_64-i386-64bit
[debug] exe versions: none
[debug] Proxy map: {}
[udemy:course] Downloading login popup



错误:

ERROR: Unable to download webpage: <urlopen error [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661)> (caused by URLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661)'),))
  File "/usr/local/bin/youtube-dl/youtube_dl/extractor/common.py", line 506, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 2196, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 1086, in https_open
    req, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)

最佳答案

根据 phihag's hint ,您的 SSL 版本太旧。

如果您还没有升级 python,这是一个简单的解决方案。但是,由于您的问题被标记为 python3 并且您的调试输出正在谈论 python2,因此您可能没有在您的系统上使用最新的 SSL 证书。

我怀疑你是否使用:

python3 `which youtube-dl` yoururl

然后它会起作用。

关于python-3.x - 如何修复 Python 中的 urlopen 错误?使用 youtube-dl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47128086/

相关文章:

python-3.x - 类型错误 : conversion from Series to Decimal is not supported

python - 如何点击表单中的提交按钮?

python - 无法从文本文件中打印特定行

python - 有没有办法将 python nos2 映射到安装在自定义位置的覆盖插件?

google-app-engine - #05919769 为自定义域启用 SSL 时的重定向循环

Google App Engine(Java) 上的安全性 - Servlet SSL?

python - libcurl 链接时 ssl 后端 (openssl) 不同于编译时 ssl 后端(无/其他)

c++ - 使用 boost::asio ssl 服务器减少每次连接的内存使用

python - 使用客户端证书的自定义 urllib 开启器

linux - Google Assistant 获取 SSL 错误