base64

Cannot convert base64 string into image

Cannot convert base64 string into image Question: Can someone help me turn this base64 data into image? I don’t know if it’s because the data was not decoded properly or anything else. Here is how I decoded the data: import base64 c_data = { the data in the link (string type) } c_decoded = base64.b64decode(c_data) …

Total answers: 2

Base64 Binary String representation to float convertion

Base64 Binary String representation to float convertion Question: I did a lot of research and can’t seem to find the answer for this, e.g: link1 link2 So I have this base64 encoded string: BzM=, and I know that the correct value is 18.43 This value comes from a decimal field from a MySql database with …

Total answers: 1

AttributeError: 'function' object has no attribute 'b64encode' python 3.9 base64 encoding string fail

AttributeError: 'function' object has no attribute 'b64encode' python 3.9 base64 encoding string fail Question: import base64 def base64(text): newText = base64.b64encode(text.encode()) return newText This is function the main calls with input, gets string and returns the encoded string. I keep on getting the following error- AttributeError: ‘function’ object has no attribute ‘b64encode’ I have tried …

Total answers: 2

How to create Base64 encode SHA256 string in Javascript?

How to create Base64 encode SHA256 string in Javascript? Question: I want to log script hashes to implement content security policy. I have been able to generate the hash in python with the following code: import hashlib import base64 string=”’ //<![CDATA[ var theForm = document.forms[‘ctl00’]; if (!theForm) { theForm = document.ctl00; } function __doPostBack(eventTarget, eventArgument) …

Total answers: 3

Conversion Between Base 64 String and Byte Array Varies in C# and Python

Conversion Between Base 64 String and Byte Array Varies in C# and Python Question: I have a C# byte array b_a that has 16 byte length. When I convert b_a to base 64 string aaa, it’s length returns 24 string aaa = Convert.ToBase64String(b_a); Console.WriteLine(aaa.Length); //24 Console.WriteLine(aaa); //’xKKkTjcKsfBDqpIJBKn6QQ==’ I want to convert aaa string to byte …

Total answers: 1

How can I base64 encode using a custom letter set?

How can I base64 encode using a custom letter set? Question: I am trying to base64 encode using a custom character set in python3. Most of the examples I have seen in SO are related to Python 2, so I had to make some minor adjustments to the code. The issue that I am facing …

Total answers: 2

Why does base64 encode return bytes instead of string directly?

Why does base64 encode return bytes instead of string directly? Question: import base64 base64.b64encode(b’bytes required’) >>>b’Ynl0ZXMgcmVxdWlyZWQ=’ If I understand correctly, base64 is a bytes <—-> string notation. Then why doesn’t it give me string ‘Ynl0ZXMgcmVxdWlyZWQ=’ directly? Or does it expect me to do some decoding furthermore? Like b’Ynl0ZXMgcmVxdWlyZWQ=’.decode(‘ascii’) or b’Ynl0ZXMgcmVxdWlyZWQ=’.decode(‘utf-8’) ? But they result in …

Total answers: 1

How to encode list of numbers as base64

How to encode list of numbers as base64 Question: I have a list containing negative numbers, and want to encode the list with base64. How can I do that? I tried: l = [-10, -48, 100, -20] bytes(l) But I get the error: ValueError: bytes must be in range(0, 256) I expect the same output …

Total answers: 1

Got black image when decode base64

Got black image when decode base64 Question: When I decode a base64 encoded cropped face image, it goes black and the data corrupts. This is the piece of code: def create_learn_msg(db_name, person_name, last_location, images, labels): json_string = {} cv2.imwrite(‘%s/%s.png’ % (“faces/”, “original-image”), images[1]) print(type(images[1])) # <type ‘numpy.ndarray’> image_string = images[1].tostring() encode_string = base64.b64encode(image_string) # Decode …

Total answers: 2

How to convert a PDF from base64 string to a file?

How to convert a PDF from base64 string to a file? Question: I have a PDF as a base64 string and I need to write it to file using Python. I tried this: import base64 base64String = “data:application/pdf;base64,JVBERi0xLjQKJeHp69MKMSAwIG9iago8PC9Qcm9kdWNlciAoU2tpYS9…” with open(‘temp.pdf’, ‘wb’) as theFile: theFile.write(base64.b64decode(base64String)) But it didn’t create a valid PDF file. What am I …

Total answers: 5