Skip to content

Commit

Permalink
py[2|3] Make encodings compatible
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Asleson <tasleson@redhat.com>
  • Loading branch information
tasleson committed Feb 13, 2017
1 parent c685ea8 commit 45ba27a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions targetd/main.py
Expand Up @@ -69,8 +69,9 @@ def do_POST(self):

# get basic auth string, strip "Basic "
try:
auth64 = self.headers.getheader("Authorization")[6:]
in_user, in_pass = auth64.decode('base64').split(":")
auth_bytes = self.headers.get("Authorization")[6:].encode('utf-8')
auth_str = base64.b64decode(auth_bytes).decode('utf-8')
in_user, in_pass = auth_str.split(":")
except Exception as e:
self.send_error(400)
return
Expand All @@ -86,8 +87,8 @@ def do_POST(self):
try:
error = (-1, "jsonrpc error")
try:
content_len = int(self.headers.getheader('content-length'))
req = json.loads(self.rfile.read(content_len))
content_len = int(self.headers.get('content-length'))
req = json.loads(self.rfile.read(content_len).decode('utf-8'))
except ValueError:
# see http://www.jsonrpc.org/specification for errcodes
error = (-32700, "parse error")
Expand Down Expand Up @@ -138,7 +139,7 @@ def do_POST(self):
rpcdata = json.dumps(
dict(error=dict(code=error[0], message=error[1]), id=id_num))
finally:
self.wfile.write(rpcdata)
self.wfile.write(rpcdata.encode('utf-8'))


class HTTPService(HTTPServer, object):
Expand Down
2 changes: 1 addition & 1 deletion targetd/utils.py
Expand Up @@ -67,4 +67,4 @@ def invoke(cmd, raise_exception=True):
(cmd_str, str(c.returncode),
str(out[0] + out[1])))

return c.returncode, out[0], out[1]
return c.returncode, out[0].decode('utf-8'), out[1].decode('utf-8')

0 comments on commit 45ba27a

Please sign in to comment.