From 8d38b43cc1cde88f5077337aac1fc0d6b4640612 Mon Sep 17 00:00:00 2001 From: Daniel McDonald Date: Wed, 28 Jun 2023 14:27:28 -0700 Subject: [PATCH] BUG: allow posting with bytes --- redbiom/_requests.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/redbiom/_requests.py b/redbiom/_requests.py index 916287b..ba4473e 100644 --- a/redbiom/_requests.py +++ b/redbiom/_requests.py @@ -6,12 +6,17 @@ def _parse_validate_request(req, command): return req.json()[command] -def _format_request(context, command, other): +def _format_request(context, command, other, as_bytes=False): """Merge commands, context and payload""" if context is None: - return "%s/%s.json" % (command, other) + data = "%s/%s.json" % (command, other) else: - return "%s/%s:%s.json" % (command, context, other) + data = "%s/%s:%s.json" % (command, context, other) + + if as_bytes: + return data.encode('utf-8') + else: + return data def get_session(): @@ -55,7 +60,8 @@ def f(context, cmd, payload): else: def f(context, cmd, payload, verbose=False): req = s.post(config['hostname'], - data=_format_request(context, cmd, payload)) + data=_format_request(context, cmd, payload, + as_bytes=True)) if verbose: print(context, cmd, payload[:100])