Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when generating Kinesis event #589

Closed
phoenik opened this issue Jul 30, 2018 · 2 comments
Closed

TypeError when generating Kinesis event #589

phoenik opened this issue Jul 30, 2018 · 2 comments
Labels
area/local/generate-event sam local generate-event command type/bug

Comments

@phoenik
Copy link

phoenik commented Jul 30, 2018

Description: TypeError occurs when generating a Kinesis event.
TypeError: Object of type bytes is not JSON serializable

Steps to reproduce the issue:

  1. Run sam local generate-event kinesis

Observed result:

Traceback (most recent call last):
  File "/Users/redacted/Library/Python/3.7/bin/sam", line 11, in <module>
    sys.exit(cli())
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/samcli/commands/local/generate_event/kinesis/cli.py", line 36, in cli
    do_cli(ctx, region, partition, sequence, data)  # pragma: no cover
  File "/Users/redacted/Library/Python/3.7/lib/python/site-packages/samcli/commands/local/generate_event/kinesis/cli.py", line 47, in do_cli
    event = json.dumps(event_dict, indent=4)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable

Expected result:
Default event json output.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Mac 10.13.6
Python 3.6, Python 3.7

Output of sam --version:
SAM CLI, version 0.5.0
and
SAM CLI, version 0.4.0

Optional Debug logs:

Add --debug flag to command you are running

Additional Details:
commands/local/generate_event/kinesis/cli.py:45
date_base64 = base64.urlsafe_b64encode(data.encode('utf8'))
This returns a b'' (byte) type which cannot be serialized by json.dump changing the line to
date_base64 = base64.urlsafe_b64encode(data.encode('utf8')).decode('utf-8') fixes the issue.

@jfuss
Copy link
Contributor

jfuss commented Aug 13, 2018

This issues has been addressed as part of the update to generate-event and in a wider scope than just the Kinesis event.

Marking this as waiting for release.

@jfuss jfuss added the stage/waiting-for-release Fix has been merged to develop and is waiting for a release label Aug 13, 2018
@jfuss
Copy link
Contributor

jfuss commented Aug 29, 2018

Closing this as it was released in 0.6.0

@jfuss jfuss closed this as completed Aug 29, 2018
@jfuss jfuss removed the stage/waiting-for-release Fix has been merged to develop and is waiting for a release label Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/generate-event sam local generate-event command type/bug
Projects
None yet
Development

No branches or pull requests

2 participants