Skip to content

Commit

Permalink
BUG: allow posting with bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
wasade committed Jun 28, 2023
1 parent 058a4e8 commit 8d38b43
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions redbiom/_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 8d38b43

Please sign in to comment.