diff --git a/metrics.py b/metrics.py index 5cdd96a8e7..37f3a8ac23 100644 --- a/metrics.py +++ b/metrics.py @@ -185,7 +185,7 @@ class MetricsCollector(object): # so that we are able to return immediately, leaving the upload running in # the background. p = subprocess.Popen([sys.executable, UPLOAD_SCRIPT], stdin=subprocess.PIPE) - p.stdin.write(json.dumps(self._reported_metrics)) + p.stdin.write(json.dumps(self._reported_metrics).encode('utf-8')) def _collect_metrics(self, func, command_name, *args, **kwargs): # If we're already collecting metrics, just execute the function. diff --git a/metrics_utils.py b/metrics_utils.py index 33f4e12b3d..281b78624d 100644 --- a/metrics_utils.py +++ b/metrics_utils.py @@ -168,7 +168,7 @@ def get_git_version(): ['git', '--version'], stdout=subprocess2.PIPE, stderr=subprocess2.PIPE) stdout, _ = p.communicate() - match = GIT_VERSION_RE.match(stdout) + match = GIT_VERSION_RE.match(stdout.decode('utf-8')) if not match: return None return '%s.%s.%s' % match.groups() diff --git a/tests/metrics_test.py b/tests/metrics_test.py index 28b65d2064..0e6973ae1e 100644 --- a/tests/metrics_test.py +++ b/tests/metrics_test.py @@ -705,7 +705,7 @@ class MetricsUtilsTest(unittest.TestCase): def test_get_git_version(self, mockPopen): """Tests that we can get the git version.""" mockProcess = mock.Mock() - mockProcess.communicate.side_effect = [('git version 2.18.0.123.foo', '')] + mockProcess.communicate.side_effect = [(b'git version 2.18.0.123.foo', '')] mockPopen.side_effect = [mockProcess] self.assertEqual('2.18.0', metrics_utils.get_git_version()) @@ -714,7 +714,7 @@ class MetricsUtilsTest(unittest.TestCase): def test_get_git_version_unrecognized(self, mockPopen): """Tests that we can get the git version.""" mockProcess = mock.Mock() - mockProcess.communicate.side_effect = [('Blah blah blah', 'blah blah')] + mockProcess.communicate.side_effect = [(b'Blah blah blah', 'blah blah')] mockPopen.side_effect = [mockProcess] self.assertIsNone(metrics_utils.get_git_version()) diff --git a/upload_metrics.py b/upload_metrics.py index cbe2dcf9d1..41fd1930af 100644 --- a/upload_metrics.py +++ b/upload_metrics.py @@ -4,18 +4,19 @@ # found in the LICENSE file. import sys -import urllib2 + +from third_party.six.moves import urllib +from third_party.six.moves import input # pylint: disable=redefined-builtin import metrics_utils def main(): - metrics = raw_input() + metrics = input() try: - urllib2.urlopen(metrics_utils.APP_URL + '/upload', metrics) - except urllib2.HTTPError: - pass - except urllib2.URLError: + urllib.request.urlopen( + metrics_utils.APP_URL + '/upload', metrics.encode('utf-8')) + except (urllib.error.HTTPError, urllib.error.URLError): pass return 0