Replace urllib.request with requests
This commit is contained in:
parent
c8089d7017
commit
0951971783
|
@ -6,22 +6,22 @@ from builtins import str
|
|||
from builtins import range
|
||||
import ast
|
||||
import logging
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
import ckanext.googleanalytics.commands as commands
|
||||
import paste.deploy.converters as converters
|
||||
import ckan.lib.helpers as h
|
||||
import ckan.plugins as p
|
||||
import ckan.plugins.toolkit as tk
|
||||
import urllib.request, urllib.error, urllib.parse
|
||||
import urllib.parse
|
||||
from ckan.exceptions import CkanVersionException
|
||||
import threading
|
||||
import requests
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
tk.requires_ckan_version("2.9")
|
||||
except CkanVersionException:
|
||||
from ckanext.googleanalytics.plugin.paster_plugin import GAMixinPlugin
|
||||
from ckanext.googleanalytics.plugin.pylons_plugin import GAMixinPlugin
|
||||
else:
|
||||
from ckanext.googleanalytics.plugin.flask_plugin import GAMixinPlugin
|
||||
|
||||
|
@ -45,14 +45,11 @@ class AnalyticsPostThread(threading.Thread):
|
|||
data = urllib.parse.urlencode(data_dict)
|
||||
log.debug("Sending API event to Google Analytics: " + data)
|
||||
# send analytics
|
||||
urllib.request.urlopen(
|
||||
res = requests.post(
|
||||
"http://www.google-analytics.com/collect",
|
||||
data,
|
||||
# timeout in seconds
|
||||
# https://docs.python.org/2/library/urllib2.html#urllib2.urlopen
|
||||
10,
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
# signals to queue job is done
|
||||
self.queue.task_done()
|
||||
|
||||
|
|
|
@ -71,7 +71,6 @@ def _post_analytics(
|
|||
):
|
||||
|
||||
from ckanext.googleanalytics.plugin import GoogleAnalyticsPlugin
|
||||
|
||||
if tk.config.get("googleanalytics.id"):
|
||||
data_dict = {
|
||||
"v": 1,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
gdata>=2.0.0
|
||||
google-api-python-client>=1.6.1, <1.7.0
|
||||
pyOpenSSL>=16.2.0
|
||||
future>=0.18.2
|
||||
|
|
Loading…
Reference in New Issue