From: Frédéric Péters Date: Wed, 8 Jan 2020 15:07:19 +0000 (+0100) Subject: load-piwik-stats: make request using requests module X-Git-Tag: v2021~247 X-Git-Url: https://git.0d.be/?p=panikdb.git;a=commitdiff_plain;h=bfe1687be29b5629f87c6cfa9cd27e6fe7b3ed89 load-piwik-stats: make request using requests module --- 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: