mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 09:27:23 -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 urllib2
|
||||
|
||||
from redash.query_runner import *
|
||||
import requests
|
||||
from redash.query_runner import BaseQueryRunner, register
|
||||
|
||||
|
||||
class Url(BaseQueryRunner):
|
||||
@@ -40,20 +38,19 @@ class Url(BaseQueryRunner):
|
||||
|
||||
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:
|
||||
error = "Error reading data from '%s'" % url
|
||||
error = "Got empty response from '{}'.".format(url)
|
||||
|
||||
return json_data, error
|
||||
|
||||
except urllib2.URLError as e:
|
||||
except requests.RequestException as e:
|
||||
return None, str(e)
|
||||
except KeyboardInterrupt:
|
||||
error = "Query cancelled by user."
|
||||
json_data = None
|
||||
except Exception as e:
|
||||
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
||||
|
||||
return json_data, error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user