From 587203d9ecbb5588bd86e969ff9a63d60a486ef6 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 22 Nov 2017 18:23:41 +0800 Subject: [PATCH] catch CURLE_UNSUPPORTED_PROTOCOL errors fixes #63 --- nvchecker/source/tornado_httpclient.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nvchecker/source/tornado_httpclient.py b/nvchecker/source/tornado_httpclient.py index e8f930d..a87d098 100644 --- a/nvchecker/source/tornado_httpclient.py +++ b/nvchecker/source/tornado_httpclient.py @@ -2,7 +2,6 @@ # Copyright (c) 2013-2017 lilydjwg , et al. import json -import asyncio from urllib.parse import urlencode from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPResponse @@ -18,9 +17,17 @@ except ImportError: __all__ = ['session'] client = AsyncHTTPClient() +HTTP2_AVAILABLE = None if pycurl else False 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) class Session: