From bfe1687be29b5629f87c6cfa9cd27e6fe7b3ed89 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 8 Jan 2020 16:07:19 +0100 Subject: [PATCH] load-piwik-stats: make request using requests module --- panikdb/stats/management/commands/load-piwik-stats.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/panikdb/stats/management/commands/load-piwik-stats.py b/panikdb/stats/management/commands/load-piwik-stats.py index 3390856..8aa4750 100644 --- a/panikdb/stats/management/commands/load-piwik-stats.py +++ b/panikdb/stats/management/commands/load-piwik-stats.py @@ -1,6 +1,6 @@ import datetime import json -import urllib2 +import requests from django.conf import settings from django.core.management.base import BaseCommand, CommandError @@ -18,11 +18,10 @@ class Command(BaseCommand): 'secondaryDimension=eventName&idSite=%(piwik_site_id)s&'\ 'period=day&date=last2&format=json&'\ 'token_auth=%(piwik_token_auth)s&expanded=1' % locals() - request = urllib2.Request(url) - request.add_header('Accept', 'application/json') if self.verbose: print('calling piwik') - result = json.load(urllib2.urlopen(request)) + response = requests.get(url, headers={'Accept': 'application/json'}) + result = response.json() if self.verbose: print('collecting results') for day in result: -- 2.39.2