美文网首页
Web编程:CGI 和 WSGI

Web编程:CGI 和 WSGI

作者: mpyl | 来源:发表于2019-07-16 15:00 被阅读0次

    关于报错
    Message: CGI script is not executable ('/cgi-bin/friendsA.py')
    是因为 friendsA.py 文件的权限问题,没有执行权限所致,只需

    chmod +x friendsA.py
    

    关于报错

    Exception happened during processing of request from ('127.0.0.1', 50325)
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/server.py", line 1126, in run_cgi
        os.execve(scriptfile, args, env)
    OSError: [Errno 8] Exec format error: '/Users/mac/Documents/core_python/WebP/cgi-bin/friendsA.py'
    

    找了很多试过很多都没解决,以下是我的代码:

    __Author__ = "noduez"
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # @Time    : 2019/7/15 7:13 PM
    # @File    : friendsA.py
    # @Software: PyCharm
    
    import cgi
    
    reshtml = '''Content-type: text/html\r\n\r\n
    <html><head><title>
    Friends CGI Demo (dynamic screen)
    </title></head>
    <body><h3>Friends list for:<i>%s</i></h3>
    Your name is: <b>%s</b><p>
    You have <b>%s</b> friends.
    </body></html>'''
    
    form  = cgi.FieldStorage()
    who = form['person'].value
    howmany = form['howmany'].value
    print(reshtml % (who, who, howmany))
    

    尝试了各种方法,经过漫长的折腾,发现了是因为这个:
    __Author__ = "noduez"
    就是这个不起眼的东西,用Pycharm新建py文件后自动生成的作者标注(其实这是我之前自己设置的),影响了本该放在第一句的
    #!/usr/bin/env python3的执行。
    简单说就是:
    __Author__ = "noduez"这句话只在pycharm里是无碍的,正常情况下最好不要把它放在文件首行,其实设置一下删掉最好,以绝后患。

    相关文章

      网友评论

          本文标题:Web编程:CGI 和 WSGI

          本文链接:https://www.haomeiwen.com/subject/hqqtlctx.html