Returning Output of Python CGI MySQL Script

后端 未结 1 1534
無奈伤痛
無奈伤痛 2021-01-22 04:42

I\'m very new to Python and MySQL and this is my first Stack question. So, apologies in advance if I\'m missing something obvious. But, I really did try to research this before

相关标签:
1条回答
  • 2021-01-22 05:05

    First, as per the CGI tutorial you link, you need to output the content type you are working with:

    print "Content-type: text/plain\r\n\r\n",
    

    If you don't at least have the newlines in there, HTTP clients will think your content is supposed to be part of the headers and get confused, they will probably assume the document you asked for is empty.

    Next, you need a CGI server. Python comes with one. Place your script in a subdirectory called cgi-bin and run this command (from the parent directory):

    python -m CGIHTTPServer
    

    The url to call will look something like this:

    curl http://localhost:8000/cgi-bin/cgitest.py
    
    0 讨论(0)
提交回复
热议问题