Merge pull request #24725 from lidizheng/add-encoding

Explicitly set encoding to ascii to prevent TypeError in Python 3
pull/24772/head
Lidi Zheng 4 years ago committed by GitHub
commit 666e24d679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/python/grpcio_tests/tests/_runner.py
  2. 6
      tools/run_tests/python_utils/port_server.py

@ -80,7 +80,7 @@ class CaptureFile(object):
value (str): What to write to the original file.
"""
if six.PY3 and not isinstance(value, six.binary_type):
value = bytes(value, 'ascii')
value = value.encode('ascii')
if self._saved_fd is None:
os.write(self._redirect_fd, value)
else:

@ -157,7 +157,7 @@ class Handler(BaseHTTPRequestHandler):
self.end_headers()
p = allocate_port(self)
self.log_message('allocated port %d' % p)
self.wfile.write(bytes('%d' % p))
self.wfile.write(str(p).encode('ascii'))
elif self.path[0:6] == '/drop/':
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
@ -177,7 +177,7 @@ class Handler(BaseHTTPRequestHandler):
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
self.wfile.write(bytes('%d' % _MY_VERSION))
self.wfile.write(str(_MY_VERSION).encode('ascii'))
elif self.path == '/dump':
# yaml module is not installed on Macs and Windows machines by default
# so we import it lazily (/dump action is only used for debugging)
@ -192,7 +192,7 @@ class Handler(BaseHTTPRequestHandler):
'in_use': dict((k, now - v) for k, v in in_use.items())
})
mu.release()
self.wfile.write(bytes(out))
self.wfile.write(out.encode('ascii'))
elif self.path == '/quitquitquit':
self.send_response(200)
self.end_headers()

Loading…
Cancel
Save