Feb-27-2021, 05:35 PM
(This post was last modified: Feb-27-2021, 05:35 PM by JohnnyCoffee.)
(Feb-27-2021, 04:41 PM)Serafim Wrote: Python tries to decode the content of the file as utf-8. You are presumably opening it with "open(path-to-file)" or "open(path-to-file, 'r')" but ought to open it with "open(path-to-file, 'rb')", 'b' for binary.
The error message stopped being displayed on the terminal, but the problem is that the figure does not render (black background appears with a white square in the middle) follows the screen print:
Here is the changed code:
# faz o loop no array comparando as extensões : while v_ext in a_ext: # Atribui path ao diretorio de arquivos estaticos, memoriza path na variable : v_filedir = "web/" + v_app + "/" + v_ass + "/" # Compara se extensões são as mesmas : elif v_ext == ".png": # Acessa o arquivo static requisitado : o_file = open(v_filedir + "fgs/" + o_fame, "rb") # Faz a leitura do arquivo : s_file = o_file.read() # Variable : obtem status de resposta para client browser : status = "200 OK" # Variable : obtem cabeçalho http para o browser do client headers = [("Content-type", "image/png; charset=utf-8")] # Function : Envio de variable para o client browser : start_response(status, headers) # Output a requisição do client browser: return s_file