catch CURLE_UNSUPPORTED_PROTOCOL errors

fixes #63
This commit is contained in:
lilydjwg 2017-11-22 18:23:41 +08:00
parent 75873b5281
commit 587203d9ec

View File

@ -2,7 +2,6 @@
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al. # Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
import json import json
import asyncio
from urllib.parse import urlencode from urllib.parse import urlencode
from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPResponse from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPResponse
@ -18,9 +17,17 @@ except ImportError:
__all__ = ['session'] __all__ = ['session']
client = AsyncHTTPClient() client = AsyncHTTPClient()
HTTP2_AVAILABLE = None if pycurl else False
def try_use_http2(curl): def try_use_http2(curl):
if pycurl: global HTTP2_AVAILABLE
if HTTP2_AVAILABLE is None:
try:
curl.setopt(pycurl.HTTP_VERSION, 4)
HTTP2_AVAILABLE = True
except pycurl.error:
HTTP2_AVAILABLE = False
elif HTTP2_AVAILABLE:
curl.setopt(pycurl.HTTP_VERSION, 4) curl.setopt(pycurl.HTTP_VERSION, 4)
class Session: class Session: