Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UnicodeDecodeError . . .
#3
(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:

[Image: view?usp=sharing]

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
Reply


Messages In This Thread
UnicodeDecodeError . . . - by JohnnyCoffee - Feb-27-2021, 03:27 PM
RE: UnicodeDecodeError . . . - by Serafim - Feb-27-2021, 04:41 PM
RE: UnicodeDecodeError . . . - by JohnnyCoffee - Feb-27-2021, 05:35 PM
RE: UnicodeDecodeError . . . - by Serafim - Feb-27-2021, 07:31 PM
RE: UnicodeDecodeError . . . - by JohnnyCoffee - Feb-27-2021, 08:47 PM
RE: UnicodeDecodeError . . . - by JohnnyCoffee - Feb-28-2021, 02:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 16: invalid cont Melcu54 3 5,586 Mar-26-2023, 12:12 PM
Last Post: Gribouillis
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 34: character Melcu54 7 20,509 Sep-26-2022, 10:09 AM
Last Post: Melcu54
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call AkaAndrew123 1 3,599 Apr-28-2021, 08:16 AM
Last Post: AkaAndrew123
  open(file, 'rb') raises UnicodeDecodeError binnybit 1 2,593 Sep-28-2020, 06:55 AM
Last Post: Gribouillis
  UnicodeDecodeError: pratheep 0 1,923 May-06-2020, 05:46 AM
Last Post: pratheep
  unicodedecodeerror:utf codec can't decode byte 0xe3 in position 1 mariolopes 3 2,946 Oct-14-2019, 10:17 PM
Last Post: mariolopes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020