Python m3u8 ssl.CertificateError -
i trying load hls m3u8 manifest file unmatched ssl certificate. using m3u8 library python. script following:
#!/usr/bin/env python urllib import quote import m3u8 import ssl input_file = quote(raw_input("please enter input file path: "), safe=':''/') #try: manifest = m3u8.load(input_file) #except ssl.certificateerror: #print "warning ssl error!" playlist in manifest.playlists: print playlist.uri print playlist.stream_info.bandwidth
so when run link reports ssl.certificateerror because ssl certificate not correct, want skip check , print ssl warning in case , continue execution of script. possible , how can it?
i have changed script to:
#!/usr/bin/env python urllib import quote import m3u8 import requests input_file = quote(raw_input("please enter input file path: "), safe=':''/') url = requests.get(input_file, verify = false) manifest = m3u8.load(url) playlist in manifest.playlists: print playlist.uri print playlist.stream_info.bandwidth
but following error:
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:852: insecurerequestwarning: unverified https request being made. adding certificate verification 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) not none file "/usr/lib/python2.7/re.py", line 141, in match return _compile(pattern, flags).match(string) typeerror: expected string or buffer
this code seems work. shows there ssl certificate error in case ssl certificate not approved.
#!/usr/bin/env python urllib import quote import m3u8 import requests import ssl in_file = quote(raw_input("please enter 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) playlist in manifest.playlists: print playlist.uri print playlist.stream_info.bandwidth
Comments
Post a Comment