diff --git a/master/buildbot/buildbot_net_usage_data.py b/master/buildbot/buildbot_net_usage_data.py index dbe6c2510c0..f73495ce3f2 100644 --- a/master/buildbot/buildbot_net_usage_data.py +++ b/master/buildbot/buildbot_net_usage_data.py @@ -21,7 +21,7 @@ from __future__ import absolute_import from __future__ import print_function -from future.moves import urllib +from future.moves.urllib import error as urllib_error from future.moves.urllib import request as urllib_request import hashlib @@ -167,7 +167,7 @@ def computeUsageData(master): def _sendWithUrlib(url, data): - data = json.dumps(data) + data = json.dumps(data).encode() clen = len(data) req = urllib_request.Request(url, data, { 'Content-Type': 'application/json', @@ -175,7 +175,7 @@ def _sendWithUrlib(url, data): }) try: f = urllib_request.urlopen(req) - except urllib.error.URLError: + except urllib_error.URLError: return None res = f.read() f.close() diff --git a/master/buildbot/newsfragments/urllib-error-import.bugfix b/master/buildbot/newsfragments/urllib-error-import.bugfix new file mode 100644 index 00000000000..cd7db5b28ba --- /dev/null +++ b/master/buildbot/newsfragments/urllib-error-import.bugfix @@ -0,0 +1,4 @@ +Make :py:class:`future.moves.urllib.error.URLError` available in the +:py:mod:`buildbot_net_usage_data` module. Fixes an exception found in +:py:func:`~buildbot_net_usage_data._sendWithUrlib` when running through the +tutorial using Python 3. diff --git a/master/buildbot/test/unit/test_buildbot_net_usage_data.py b/master/buildbot/test/unit/test_buildbot_net_usage_data.py index e8c54c4fb9f..b8ffaa206b9 100644 --- a/master/buildbot/test/unit/test_buildbot_net_usage_data.py +++ b/master/buildbot/test/unit/test_buildbot_net_usage_data.py @@ -133,7 +133,8 @@ def close(self): self.assertEqual(len(open_url), 1) self.assertEqual(open_url[0].request.args, ('https://events.buildbot.net/events/phone_home', - '{"foo": "bar"}', {'Content-Length': 14, 'Content-Type': 'application/json'})) + b'{"foo": "bar"}', + {'Content-Length': 14, 'Content-Type': 'application/json'})) def test_real(self): if "TEST_BUILDBOTNET_USAGEDATA" not in os.environ: