From d03fc80eac6d233ee8632e5b3cbf0ba13af7cc92 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sat, 5 May 2018 00:50:42 -0300 Subject: [PATCH] make analytics use treq --- lbrynet/analytics.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lbrynet/analytics.py b/lbrynet/analytics.py index debd99728..6cd1f1e69 100644 --- a/lbrynet/analytics.py +++ b/lbrynet/analytics.py @@ -1,8 +1,8 @@ import collections import logging + +import treq from twisted.internet import defer, task -from requests import auth -from txrequests import Session from lbrynet import conf from lbrynet.core import looping_call_manager, utils, system_info @@ -216,8 +216,8 @@ class Manager(object): class Api(object): - def __init__(self, session, url, write_key, enabled): - self.session = session + def __init__(self, cookies, url, write_key, enabled): + self.cookies = cookies self.url = url self._write_key = write_key self._enabled = enabled @@ -232,14 +232,17 @@ class Api(object): # timeout will have expired. # # by forcing the connection to close, we will disable the keep-alive. + + def update_cookies(response): + self.cookies.update(response.cookies()) + return response + assert endpoint[0] == '/' - headers = {"Connection": "close"} - return self.session.post( - self.url + endpoint, - json=data, - auth=auth.HTTPBasicAuth(self._write_key, ''), - headers=headers - ) + headers = {b"Connection": b"close"} + d = treq.post(self.url + endpoint, auth=(self._write_key, ''), json=data, + headers=headers, cookies=self.cookies) + d.addCallback(update_cookies) + return d def track(self, event): """Send a single tracking event""" @@ -257,11 +260,10 @@ class Api(object): @classmethod def new_instance(cls, enabled=None): """Initialize an instance using values from the configuration""" - session = Session() if enabled is None: enabled = conf.settings['share_usage_data'] return cls( - session, + {}, conf.settings['ANALYTICS_ENDPOINT'], utils.deobfuscate(conf.settings['ANALYTICS_TOKEN']), enabled,