diff --git a/bazarr/analytics.py b/bazarr/analytics.py index 51e4e3770..2dd5274ad 100644 --- a/bazarr/analytics.py +++ b/bazarr/analytics.py @@ -6,6 +6,8 @@ import base64 import random import platform import os +import logging +import codecs from pyga.requests import Event, Page, Tracker, Session, Visitor, Config from pyga.entities import CustomVariable @@ -29,11 +31,11 @@ def track_event(category=None, action=None, label=None): try: if settings.analytics.visitor: - visitor = pickle.loads(base64.b64decode(settings.analytics.visitor), encoding='utf-8') - if visitor.user_agent is None: - visitor.user_agent = os.environ.get("SZ_USER_AGENT") - if visitor.unique_id > int(0x7fffffff): - visitor.unique_id = random.randint(0, 0x7fffffff) + visitor = pickle.loads(codecs.decode(settings.analytics.visitor.encode(), "base64")) + if visitor.user_agent is None: + visitor.user_agent = os.environ.get("SZ_USER_AGENT") + if visitor.unique_id > int(0x7fffffff): + visitor.unique_id = random.randint(0, 0x7fffffff) except: visitor = Visitor() visitor.unique_id = random.randint(0, 0x7fffffff) @@ -56,8 +58,9 @@ def track_event(category=None, action=None, label=None): try: tracker.track_event(event, session, visitor) except: + logging.debug("BAZARR unable to track event.") pass else: - settings.analytics.visitor = base64.b64encode(pickle.dumps(visitor)) + settings.analytics.visitor = codecs.encode(pickle.dumps(visitor), "base64").decode() with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: settings.write(handle) diff --git a/libs/pyga/requests.py b/libs/pyga/requests.py index 72e4bc953..2497c857d 100644 --- a/libs/pyga/requests.py +++ b/libs/pyga/requests.py @@ -5,6 +5,7 @@ import calendar from math import floor from pyga.entities import Campaign, CustomVariable, Event, Item, Page, Session, SocialInteraction, Transaction, Visitor import pyga.utils as utils +from six import itervalues try: from urllib import urlencode from urllib2 import Request as urllib_request @@ -210,7 +211,7 @@ class Request(GIFRequest): x10.clear_key(self.X10_CUSTOMVAR_VALUE_PROJCT_ID) x10.clear_key(self.X10_CUSTOMVAR_SCOPE_PROJECT_ID) - for cvar in custom_vars.itervalues(): + for cvar in itervalues(custom_vars): name = utils.encode_uri_components(cvar.name) value = utils.encode_uri_components(cvar.value) x10.set_key(