question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DynamoDB's Binary type issues with Python 3

See original GitHub issue

The Binary class has a problematic implementation of the __str__() method that assumes str and bytes are interchangeable. Example:

Python 3.5.2 (default, Sep 28 2016, 18:11:34)
>>> from boto3.dynamodb.types import Binary
>>> b = Binary(b'hello')

>>> b
Binary(b'hello')

>>> print(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __str__ returned non-string (type bytes)

>>> bytes(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Binary' object is not iterable

The above examples all succeed under Python 2.7.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:13
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
mhballcommented, Jun 21, 2019

I encountered this issue also. Found I could work around it by accessing the value directly. E.g.

Python 3.5.2 (default, Nov 12 2018, 13:43:14)
>>> from boto3.dynamodb.types import Binary
>>> b = Binary(b'hello')
>>> b
Binary(b'hello')

>>> print(b.value)
b'hello'

>>> print(b.value.decode("utf-8"))
hello
3reactions
scribucommented, Sep 20, 2018

Why is this marked as feature-request? It’s a bug that happens in Python3.

Also, why is the Binary wrapper class needed at all?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to parse AWS DynamoDB binary get ... - Stack Overflow
class Binary: """A class for representing Binary in dynamodb Especially for Python 2, ... Unicode and Python 3 string types are not allowed....
Read more >
Source code for boto3.dynamodb.types - AWS
It is essentially a wrapper around binary. Unicode and Python 3 string types are not allowed. """ def __init__(self, value): if not isinstance(value, ......
Read more >
Error handling with DynamoDB - AWS Documentation
Discover the best practices for handling client and server errors and exceptions returned by Amazon DynamoDB operations.
Read more >
The Three DynamoDB Limits You Need to Know - Alex DeBrie
In other cases, the limit may alter how you structure your solution, such as how the 15 minute limit on Lambda execution time...
Read more >
Unable to parse AWS DynamoDB binary get item in boto3 ...
Unicode and Python 3 string types are not allowed. """ def __init__(self, value): if not isinstance(value, BINARY_TYPES): types = ', '.join([str(t) for t...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found