Convert to list a string from a list that contains Base64?

Asked

Viewed 86 times

2

I receive through a requisition json one request.POST that comes as a list of string Base64.

I can convert to string with str(request.POST['imagem']) what results something like this:

['eJzFnemyozqwpQXeNdz7/i/bHWXTP7zTXiy+lZKrTkQrwmHQkJNyATYfv36dWzHGGPfxhhjPB6P', ...]

With the AST library on any other list of the same type I can convert to a list of python with: ast.literal_eval(list_string), but when it comes with Base64 inside the list, it gives syntax error:

File "", line 2 eJzFnemyozqwpQXeNdz7/i/bHWXTP7zTXiy+lZKrTkQrwmHQkJNyATYfv36dWzHGGPfxhhjPB6P Syntaxerror: invalid syntax

Any idea?

How to convert this to a usable list of python?

  • import base64 
base64.b64decode(coded_string). Please try this way

1 answer

1

If your answer is a valid json you can do as follows:

import json

lista = json.dumps(request.POST['imagem'])

And just like that.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.