Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • str.encode() in python3.x uses utf-8 by default docs.python.org/3/library/stdtypes.html#str.encode Commented Feb 3, 2013 at 21:10
  • It looks like your friend sent you repr(data) instead of just data. Show the code doing the sending and we can fix the right problem. Commented Feb 3, 2013 at 21:27
  • base64.b64encode(...) returns bytes, so how is it sent to the client? Commented Feb 3, 2013 at 21:32
  • edited, turn out it str it before senting it... Commented Feb 3, 2013 at 21:40
  • It sounds like what you really want to do is smuggle an arbitrary bytes through a str without decoding/encoding (in other words, send each byte as the Unicode codepoint with the same number). This isn't impossible—but it's almost always a sign that you're doing something wrong. There's almost always a better answer. For example: If your API is byte-based, use bytes instead of str in the API; if your bytes are ASCII (which is always true for base64), just b.decode('ascii') to get the str; etc. Commented Feb 3, 2013 at 22:51