1

I have a cgi python script which gets data from html form, handles it and makes a table which put to html code.

The snip of the code:

# -*- coding: utf-8 -*-
import cgi

print('Content-type: text/html\n')
print()
print("""<!DOCTYPE HTML>
        <html>
        # and etc.

When I use the form I see the new page with a table but before this table I see the text string

Content-type: text/html\

How to change the python code for not displaying this string in browser. Put it in comment doesn't help.

  • I think you need to look at [this answer](https://stackoverflow.com/questions/53912765/cgi-html-to-python) – mplungjan Nov 18 '20 at 06:40
  • Thanks, but it doesn't contain the answer on my question. – Alexey Klimenko Nov 18 '20 at 07:59
  • What does the network tab say the file headers are? - can you try `print "Content-type: text/html\n\n"` – mplungjan Nov 18 '20 at 08:01
  • The response headers are: `Connection: keep-alive, Content-Encoding: gzip, Content-Type: text/html, Keep-Alive: timeout=30, Server: nginx-reuseport/1.13.4, Transfer-Encoding: chunked Vary: Accept-Encoding`, On the server is installed python v3. – Alexey Klimenko Nov 19 '20 at 05:27
  • 1
    I reopened the question. There is something weird going on. What browser? Does another browser work better? Did you clean your cache? Does a plain HTML file from the same folder work? Why do you you not have a shebang like `#!/usr/bin/python3` - Does your nginx understand and parse python CGI? – mplungjan Nov 19 '20 at 06:48
  • For example: https://techexpert.tips/nginx/python-cgi-nginx/ – mplungjan Nov 19 '20 at 06:49
  • I use chrome, but also tried in edge and iexplorer. All browsers work the same. I have a shebang with a path to python3, just missed it in snippet of code. When I inspect the page I see that the text string **Content-type: text/html** was put between and tags. All other code of the script works fine. – Alexey Klimenko Nov 19 '20 at 12:37

0 Answers0