Linked Questions
23 questions linked to/from Why do I need 'b' to encode a string with Base64?
121
votes
9
answers
263k
views
How to encode text to base64 in python [duplicate]
I am trying to encode a text string to base64.
i tried doing this :
name = "your name"
print('encoding %s in base64 yields = %s\n'%(name,name.encode('base64','strict')))
But this gives me the ...
47
votes
1
answer
104k
views
TypeError: a bytes-like object is required, not 'str' - python 2 to 3 [duplicate]
Hi I am having trouble with this error message. I am new to Python and this Python2 and Python3 is a hassle. I'm not sure what to do here, the error message is as shown below.
Using Ticker: AAPL
...
23
votes
1
answer
64k
views
Converting a string to and from Base 64 [duplicate]
I am trying to write two programs one that converts a string to base64 and then another that takes a base64 encoded string and converts it back to a string.
so far i cant get past the base64 encoding ...
20
votes
2
answers
46k
views
Encode string representation of integer to base64 in Python 3 [duplicate]
I'm trying to encode an int in to base64, i'm doing that:
foo = 1
base64.b64encode(bytes(foo))
expected output: 'MQ=='
given output: b'AA=='
what i'm doing wrong?
Edit: in Python 2.7.2 works ...
5
votes
2
answers
8k
views
when convert to base 64, TypeError: 'str' does not support the buffer interface [duplicate]
im = Image.open(filePath) # load image
self.msg = str(bytearray(list(im.getdata()))) # convert image data to string
encodedMsg = base64.b64encode(self.msg)
when I was trying to ...
2
votes
2
answers
14k
views
How to encode a string with base64 in python 3 and remove the new lines [duplicate]
Background:
I'm trying to encode my string of a username and password to base 64 for a SOAP request in python 3.5.2.
Code:
username = 'Universal API/uAPI7054626850-8a6c09f0'
password = '...
-2
votes
1
answer
351
views
TypeError: 'str' does not support the buffer interface - using base64.b64encode [duplicate]
I've taken a look at many other "Questions that may already have your answer", but didn't come across any that hit directly on the issue I'm running into.
Here's my Python 2 snippet:
...
0
votes
0
answers
209
views
pycrypto not encrypting in ascii or unicode [duplicate]
I am using pycrypto to encrypt and decrypt a message using a key. I followed some examples and finally wrote my own. But it turns out that the encrypted message is not in unicode or ascii. I need to ...
1
vote
2
answers
15k
views
How to decode base 64 format in jmeter?
Does anyone know a solution to decode a base 64 format string in JMeter?
I have to decode the a response, but i don't want to reinvent the wheel...
Do i have to write the code by myself (hope not)?
...
6
votes
1
answer
20k
views
Using requests to send byte-array to webservice using http post
Currently I'm trying to send a byte-array to a webservice, but i get the error message, that a bytearray is not serializeable:
TypeError: bytearray(b'') is not JSON serializable
I'm using the ...
2
votes
1
answer
8k
views
Encoding a string to base64 in Python 2.x vs Python 3.x
In Python 2, I used to could do this:
>>> var='this is a simple string'
>>> var.encode('base64')
'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc=\n'
Easy! Unfortunately, this don't work in Python ...
7
votes
4
answers
4k
views
Get Binary Representation of PIL Image Without Saving
I am writing an application that uses images intensively. It is composed of two parts. The client part is written in Python. It does some preprocessing on images and sends them over TCP to a Node.js ...
1
vote
1
answer
2k
views
Trying to store raw bytes inside my one Python script file
I am currently working on a Python script that will be able to hide all binary files inside itself. It does this by reading all binary data from the targeted file and then stores it in a list inside ...
0
votes
1
answer
5k
views
Python 3.7 TypeError: a bytes-like object is required, not 'str'
I have these two strings:
client_id = "id_str"
client_secret = "secret_str"
And I must pass them like so:
def getToken(code, client_id, client_secret, redirect_uri):
body = {
"grant_type"...
5
votes
1
answer
3k
views
Storing matplotlib images in S3 with S3.Object().put() on boto3 1.5.36
Amongst other things I am drawing plots using matplotlib, which I would like to immediately store as S3 objects.
According to the answers provided in this and this other question and the fine manual, ...