[Python] Apache won't working on UTF-8 how can I solve this

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    I've installed apache on my windows 10 and set the things for python and it can run .py files thats ok. But however I can't use the letter "ş" cause apache encode is not setted for utf-8 but I already added the AddDefaultCharset UTf-8 in my httpd.conf file. But when I try to open my index file I'm getting this error

    UnicodeEncodeError: 'charmap' codec can't encode character '\\u015e' in position 554: character maps to <undefined>\r: C:/www/index.py


    So how can i solve this problem?

    and this is my index file

    #!C:\Users\doganalisan\AppData\Local\Programs\Python\Python39/python.exe
    import page_elements as pe
    import background
    print("Content-Type: text/html\n\n")
    print("""
    <!DOCTYPE html>
    <html lang="tr">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/style.css">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <title>Semanur ŞAN</title>
    <script src="https://kit.fontawesome.com/657430e951.js" crossorigin="anonymous"></script>
    </head>
    <body id="index">
    <div class="container">
    """ + pe.header + """
    """ + pe.mobile_header+ """
    """ + str(background.indexaboutside()) + """
    </div>
    """ + pe.footer + """
    </body>
    </html>
    """)


    I've found the solution its so simple just adding this code on my files and its working fine

    import sys
    sys.stdout.reconfigure(encoding='utf-8')

    Continue reading...

Compartilhe esta Página