2017-03-28 14 views
-2

일치하지 않는 SSL 인증서가있는 HLS m3u8 매니페스트 파일을로드하려고합니다. 파이썬 용 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