etcd3-py icon indicating copy to clipboard operation
etcd3-py copied to clipboard

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

Open pjz opened this issue 5 years ago • 3 comments

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 avatar Mar 27 '19 16:03 pjz

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.

Revolution1 avatar Mar 27 '19 17:03 Revolution1

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!

pjz avatar Mar 27 '19 17:03 pjz

Got it

Revolution1 avatar Mar 27 '19 17:03 Revolution1