K
K
kova1ev2019-04-17 18:42:20
Python
kova1ev, 2019-04-17 18:42:20

Running cgi python script from pycharm and console, how to display Cyrillic?

Hello everyone, such a problem, I launch the built-in localhost python server, in the cgi folder there is a script that, when accessed from a browser, gives a filled html table in which the information is in Russian. So, if I run it from pycharm (where I actually write the code), then the Cyrillic alphabet in the browser is displayed normally, if I run it from the console, black diamonds with question marks are displayed instead of Cyrillic characters in the browser. I have no idea what to do, newbie.
There is a project folder, in its root is the main.py file and the cgi-bin folder
. The following code is in the main.py file:

from http.server import HTTPServer, CGIHTTPRequestHandler


server_address = ("", 8000)
httpd = HTTPServer(server_address, CGIHTTPRequestHandler)
httpd.serve_forever()

in the cgi-bin folder is the test.py script, its code is:
print("Content-type: text/html; charset=utf-8")
print()
print("проверка")

Running main.py from pycharm in a browser at localhost:8000/cgi-bin/test.py shows the word "test". Running main.py from the console shows black diamonds.
Is it possible to solve the problem somehow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Buch2002, 2020-12-23
@Buch2002

In order for your code to work correctly in the console, then bring the file to this form:

#!/usr/bin/python
# -*- coding: utf-8 -*-
print("Content-type: text/html; charset=utf-8")
print()
print("проверка")

You can read more about the syntax for declaring a Python source file encoding at this link in the examples .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question