Skip to content

Commit

Permalink
Merge pull request #3120 from jakewan/urllib-error
Browse files Browse the repository at this point in the history
Import future.moves.urllib.error explicitly
  • Loading branch information
tardyp committed Apr 18, 2017
2 parents 958d089 + 3968b5f commit 6e243a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions master/buildbot/buildbot_net_usage_data.py
Expand Up @@ -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
Expand Down Expand Up @@ -167,15 +167,15 @@ 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',
'Content-Length': clen
})
try:
f = urllib_request.urlopen(req)
except urllib.error.URLError:
except urllib_error.URLError:
return None
res = f.read()
f.close()
Expand Down
4 changes: 4 additions & 0 deletions 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.
3 changes: 2 additions & 1 deletion master/buildbot/test/unit/test_buildbot_net_usage_data.py
Expand Up @@ -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:
Expand Down

0 comments on commit 6e243a7

Please sign in to comment.