[Python] python write file "Encoding detection: utf_8 is most likely the one."

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a python script that uses a REST API to get XML files from a tool. This is the heart of it:

    def get_output(self, url, output_filename):
    xml_response = self.client.get_request(url)
    if not xml_response:
    self.logger.error(f"no xml_response:{output_filename}")
    return False
    else:
    self.logger.info(f"{output_filename}")
    output_file = open(output_filename, 'w', encoding='utf-8')
    output_file.write(xml_response.text)
    output_file.close()
    return True


    The write call causes a DEBUG log entry:

    Encoding detection: utf_8 is most likely the one.


    Is there a way to explicitly tell the write to use utf8 in order to not get that log entry?

    Thanks!

    Continue reading...

Compartilhe esta Página