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

Make obvious that etcd3 is binary-clean for keys and values, with .put() coerced to bytes #72

Open
pjz opened this issue Mar 27, 2019 · 3 comments

Comments

@pjz
Copy link
Contributor

pjz commented Mar 27, 2019

Description

I put a str into etcd and got out bytes

What I Did

k, v = "foo", "bar"
...
client.put(k, v)
...
r = client.range(k).kvs[0].key
print(f"{r:<10}")

gets me

TypeError: unsupported format string passed to bytes.__format__

What I expected

I expected to be able to round-trip data through etcd without issue. As it is now, I have to explicitly cast everything back to str() if I want to use it in a format string like above.

@pjz pjz changed the title Put in str, get out bytes ? Put in str, got out bytes ? Mar 27, 2019
@Revolution1
Copy link
Owner

Yes, that's a feature of etcd3:
Instead of etcd2 only accept ascii string as key and value,
the data type of etcd3's key&value are both binary data which is bytes in python3

so ... you have to manually convert it to str if you need.

@pjz
Copy link
Contributor Author

pjz commented Mar 27, 2019

I see. I'd suggest showing that in the short-docs to make it clear - as I said, it was quite surprising to me. Thanks for the quick reply!

@Revolution1
Copy link
Owner

Got it

@pjz pjz changed the title Put in str, got out bytes ? Make obvious that etcd3 is binary-clean for keys and values, with .put() coerced to bytes Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants