Skip to content Skip to sidebar Skip to footer

How To Solve "a Bytes-like Object Is Required, Not 'str'" In Create_message() Function?

I'm getting an error in creating a new message using create_message(). function listed over https://developers.google.com/gmail/api/guides/drafts. def create_message(sender, to, su

Solution 1:

base64.urlsafe_b64encode expects bytes, but the type of message.as_string() is str.

Use the message's as_bytes method instead.

return {'raw': base64.urlsafe_b64encode(message.as_bytes())}

Post a Comment for "How To Solve "a Bytes-like Object Is Required, Not 'str'" In Create_message() Function?"