0

Can someone say, why is the below item failing? Simple program, but I couldn't find answer anywhere

Python Code

from flask import Flask

    app = Flask(__name__)

    @app.route('/')
    def hello_world():
        return 'Hello, World!'

Results

UnicodeDecodeError: 'utf8' codec can't decode byte 0xc8 in position 0: invalid continuation byte
cizario
  • 3,995
  • 3
  • 13
  • 27
Baixa
  • 25
  • 9
  • 2
    There is no `Flask app = Flask(name)`. What you should have instead is `app=Flask(__name__)`; give it a go and let us know. – netlemon Jul 04 '20 at 07:23
  • @Baixa i just edited your question (improvement formatting), check it out and if OK you can accept it. you may know, with bad code formatting, answers vary and you can get all kind of interpreted answers. – cizario Jul 04 '20 at 07:57

1 Answers1

-1

refer to this topic (Automatic Conversion) from Flask docs

Flask expect you are using UTF-8 for encoding files (.py and .html at least)

depending on the code editor you are using you can enforce UTF-8 character encoding

for e.g have look at this thread on How do I convert an ANSI encoded file to UTF-8 with Notepad++?

Update

as per this thread the problem could be OS-related, change your server hostname to a string that only contains ASCII characters.

cizario
  • 3,995
  • 3
  • 13
  • 27
  • His problem is not related to this. He's only starting out with the simple example from the flask doc, but the way he's instantiating the application is wrong. – netlemon Jul 04 '20 at 07:24
  • @newbie99 i just edited his question (code formatting improvement) and waiting for approval and i find he already putted `app = Flask(__name__)` and NOT `Flask app = Flask(name)` you can check that with the `edit` link below the question. the double `__` is interpreted as **bold** style that's why you see `Flask app = Flask(name)` with `name` in **bold**. just remove the `down vote`. – cizario Jul 04 '20 at 07:37
  • I used UTF-8, but the problem hasn't been resolved. (used Notepad++) – Baixa Jul 04 '20 at 08:21
  • that's weird, you're just starting with the standard hello world and it seems correct. such encoding error is very common, i suggest you typing the same code using an other code editor like `VS Code` and see if there's a difference. let me know. – cizario Jul 04 '20 at 08:29
  • Used VS Code, but error hasn't been resolved. I tried reinstall python and flask, but the result hasn't changed – Baixa Jul 04 '20 at 17:26
  • I can launch this program on Linux (VirtualMachine), now I use Windows 7. Probably, the problem will disappear – Baixa Jul 04 '20 at 17:30
  • i updated my answer, let me know if that works on `Linux`. i guess the problem wont appear for `Windows`, let me know for both – cizario Jul 04 '20 at 18:18
  • Thanks a lot! Really, name of computer had russian alphebet letters, so the problem apeared. I changed name and the program has already started up succesfully! – Baixa Jul 05 '20 at 13:59
  • 1
    glade that solved your issue, would you mind give my answer an upvote just to remove -1 that doesnt make any sens , happy coding – cizario Jul 05 '20 at 14:03
  • I don’t have the opportunity to mark the answer as useful, as soon as the level rises, I’ll mark – Baixa Jul 06 '20 at 07:47