Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling special characters/utf-8 from request #60

Closed
WattageGuy opened this issue Sep 17, 2022 · 2 comments
Closed

Handling special characters/utf-8 from request #60

WattageGuy opened this issue Sep 17, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@WattageGuy
Copy link

WattageGuy commented Sep 17, 2022

According to the docs body string in HTTP response should be encoded in UTF-8 but the response cant handle special characters like "ÅÄÖ". This is the code im using:

app = Microdot()

htmldoc = '''<!DOCTYPE html>
<html>
    <head>
        <title>Microdot Example Page</title>
         <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    </head>
    <body>
        <div>
            <h1>Microdot Example Page</h1>
            <p>Test åöä</p>
            <p><a href="/shutdown">Click to shutdown the server</a></p>
            <form action="/form" method="POST" accept-charset="utf-8">
            <label for="ssid">SSID:</label><br>
            <input type="text" id="ssid" name="ssid"><br>
            <label for="password">Password:</label><br>
            <input type="password" id="password" name="password"><br>
            <input type="submit" value="Submit">
            </form>
        </div>
    </body>
</html>
'''

@app.route('/')
def hello(request):
    return htmldoc, 200, {'Content-Type': 'text/html'}

@app.route('/form', methods=['GET', 'POST'])
def index(req):
    if req.method == 'POST':
        print(req.form.get('ssid')) #  <-- This outputs Lös if the given value is Lös
        ssid = req.form.get('ssid')
        password = req.form.get('password')
        print(ssid) #  <-- This outputs Lös if the given value is Lös
        print(password) #  <-- This outputs Lös if the given value is Lös
    return f'SSID: {ssid}, Password: {password}' #  <-- This outputs Lös if the given value is Lös
@miguelgrinberg
Copy link
Owner

@WattageGuy This is actually a problem on my part. I documented how I intended this to work, but it appears I haven't implemented this fully. Fix coming soon.

@miguelgrinberg miguelgrinberg self-assigned this Sep 17, 2022
@miguelgrinberg miguelgrinberg added the bug Something isn't working label Sep 17, 2022
@miguelgrinberg
Copy link
Owner

@WattageGuy Could you please try the microblog.py in the main branch and confirm you are able to work with UTF-8 forms with it? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants