2017-03-28 6 views
-2

HLS m3u8マニフェストファイルを、不一致のSSL証明書でロードしようとしています。私はPythonのm3u8ライブラリを使用しています。私のスクリプトは以下の通りである:だから私は、SSL証明書が正しくないので、それがssl.CertificateErrorを報告し、私のリンクでそれを実行したときにPython m3u8 ssl.CertificateError

#!/usr/bin/env python 
from urllib import quote 
import m3u8 
import ssl 

input_file = quote(raw_input("Please enter the input file path: "), safe=':''/') 

#try: 
manifest = m3u8.load(input_file) 
#except ssl.CertificateError: 
#print "WARNING SSL Error!" 
for playlist in manifest.playlists: 
     print playlist.uri 
     print playlist.stream_info.bandwidth 

が、私は、このチェックをスキップして、この場合のみSSLの警告を印刷したいですスクリプトの実行を続けます。これは可能なのですか?どうすればいいですか?

私はに私のスクリプトを変更しました:

#!/usr/bin/env python 
from urllib import quote 
import m3u8 
import requests 

input_file = quote(raw_input("Please enter the input file path: "), safe=':''/') 

url = requests.get(input_file, verify = False) 

manifest = m3u8.load(url) 

for playlist in manifest.playlists: 
     print playlist.uri 
     print playlist.stream_info.bandwidth 

しかし、今、私は次のエラーを取得する:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings 
    InsecureRequestWarning) 
Traceback (most recent call last): 
    File "./open.sh", line 10, in <module> 
    manifest = m3u8.load(url) 
    File "/usr/local/lib/python2.7/dist-packages/m3u8/__init__.py", line 44, in load 
    if is_url(uri): 
    File "/usr/local/lib/python2.7/dist-packages/m3u8/parser.py", line 337, in is_url 
    return re.match(r'https?://', uri) is not None 
    File "/usr/lib/python2.7/re.py", line 141, in match 
    return _compile(pattern, flags).match(string) 
TypeError: expected string or buffer 
+0

おそらく最初に内容を読んでからパーサーに送信する必要があります。 http://stackoverflow.com/questions/15445981/how-do-i-disable-the-security-certificate-check-in-python-requests – pvg

+0

@pvgはい、私がurllibを使ってこのエラーを回避する方法を知っていますか?ライブラリをリクエストしていますが、そのためにm3u8ライブラリを使用したいと思います。urllibに基づいていても、 'verify = False'をサポートしていません。すでに試してみました。 –

+0

あなたは何を試しましたか?あなたの質問は何ですか?パーサはあなたに必要なコントロールを提供しません。例外が発生した後も継続することはできません。データを読み込んでパーザに渡してください。問題は何ですか? – pvg

答えて

0

このコードが動作しているようです。また、SSL証明書が承認されていない場合にSSL証明書エラーが発生していることを示しています。

#!/usr/bin/env python 
from urllib import quote 
import m3u8 
import requests 
import ssl 

in_file = quote(raw_input("Please enter the input file path: "), safe=':''/') 

try: 
     url = requests.get(in_file) 
except requests.exceptions.SSLError: 
     url = requests.get(in_file, verify = False) 
     print "Warning: SSL Certificate Error!!!" 
     print 
     pass 

manifest = m3u8.loads(url.text) 

for playlist in manifest.playlists: 
     print playlist.uri 
     print playlist.stream_info.bandwidth 
関連する問題