mirror of
https://github.com/getredash/redash.git
synced 2025-12-20 09:57:35 -05:00
Merge pull request #1395 from getredash/012patches
Change: switch to requests in URL query runner
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import sys
|
import requests
|
||||||
import urllib2
|
from redash.query_runner import BaseQueryRunner, register
|
||||||
|
|
||||||
from redash.query_runner import *
|
|
||||||
|
|
||||||
|
|
||||||
class Url(BaseQueryRunner):
|
class Url(BaseQueryRunner):
|
||||||
@@ -40,20 +38,19 @@ class Url(BaseQueryRunner):
|
|||||||
|
|
||||||
url = base_url + query
|
url = base_url + query
|
||||||
|
|
||||||
json_data = urllib2.urlopen(url).read().strip()
|
response = requests.get(url)
|
||||||
|
response.raise_for_status()
|
||||||
|
json_data = response.content.strip()
|
||||||
|
|
||||||
if not json_data:
|
if not json_data:
|
||||||
error = "Error reading data from '%s'" % url
|
error = "Got empty response from '{}'.".format(url)
|
||||||
|
|
||||||
return json_data, error
|
return json_data, error
|
||||||
|
except requests.RequestException as e:
|
||||||
except urllib2.URLError as e:
|
|
||||||
return None, str(e)
|
return None, str(e)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
error = "Query cancelled by user."
|
error = "Query cancelled by user."
|
||||||
json_data = None
|
json_data = None
|
||||||
except Exception as e:
|
|
||||||
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
|
||||||
|
|
||||||
return json_data, error
|
return json_data, error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user