Closed carver closed 4 years ago
Noting that this will result in string
values that cannot be decoded due to containing invalid UTF8 characters, but I think this is ok since the docs for the string
type state that it is assumed to be UTF8 encoded.
assumed to be UTF8 encoded
Right, although it might be desirable for users to retrieve the bytes
data even if it's not valid utf8. (rather than just crash)
Maybe would should use something like .decode("utf-8", "replace")
. Although I kind of hate it already, the idea that broken strings won't be noticed early on. I'm just not sure how else to reasonably give people access to malformed data. Maybe we just don't. If you want malformed data, you write a curl call to the json-rpc.
I guess I landed on: crash if not valid utf8.
How about we raise a custom error message that is as informative as possible when this happens.
The returned type for this function is
string
which is expected to be a UTF8 encoded string of text. The returned value ... could not be decoded as valid UTF8. This is indicative of a broken application which is using incorrect return types for binary data.
Im going to work on this because it will simplify the log data filter for web3: https://github.com/ethereum/web3.py/pull/953
Just to recap, to see that Im understanding.
Correct
:+1: I think this will require a major version bump.
I suppose this is fixed.
What was wrong?
I would expect that decoding an abi value of
string
would return astr
-typed value.I expected
('mystr',)
How can it be fixed?
Last step of decoding should be to call
.decode('utf8')
on a bytes value if using a string decoder.