V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zhuyalin
V2EX  ›  Python

Python 打包的 EXE 在加载 CGI 时报错

  •  
  •   zhuyalin · 2018-05-09 08:08:28 +08:00 · 2073 次点击
    这是一个创建于 2185 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近做了一个小程序,直接在 Python 环境下运行,无论是 Windows 或是 Linux 都没问题。打包后,在 Linux 上也没问题。只是在 Windows 下,只要访问到其中的 CGI 文件时,就会出现这样的错误:

    127.0.0.1 - - [09/May/2018 08:04:35] "GET /cgi-bin/main.py HTTP/1.1" 200 - 127.0.0.1 - - [09/May/2018 08:04:35] command: D:\damai\server.exe -u D:\damai\cg i-bin\main.py "" 127.0.0.1 - - [09/May/2018 08:04:37] b'[3472] Failed to execute script server\r
    nTraceback (most recent call last):\r\n File "server.py", line 73, in <module>
    r\n welcome()\r\n File "server.py", line 41, in welcome\r\n mod_choice=st r(input("\xc7\xeb\xd1\xa1\xd4\xf1\xa3\xba"))\r\nEOFError: EOF when reading a lin e\r\n'

    事实上,错误中提到的 welcome 函数在未打包或是 Linux 打包的情况下都没有问题。涉及 CGI 的代码没有打包,直接放在相对路径目录下运行。

    请高手指点,谢谢!

    第 1 条附言  ·  2018-05-09 08:45:15 +08:00
    其中涉及的 welcome 函数代码如下:
    def welcome():
    print('TIP1')
    print('HTTPS://AILS.TOP')
    print('=='*16)
    print('TIP2')
    print('TIP3,请按 1')
    print('TIP4,请按 2')
    print('退出请按 0')
    print('=='*16)
    mod_choice=str(input("请选择:"))
    if mod_choice=="1":
    print("请在下面输入完整文件路径")
    fullpath=str(input(""))
    if os.path.isfile(fullpath):
    add_path(fullpath)
    qr_url="http://"+ip+":8080/cgi-bin/download.py?filename="+path
    creatQR(qr_url)
    else:
    print(colored("WARNING:您输入的文件不存在!","yellow"))
    print()
    welcome()
    elif mod_choice=="2":
    print("请输入需要浏览的目录")
    fullpath=str(input(""))
    add_path(fullpath)

    elif mod_choice=='0':
    exit()
    else:
    print(colored("您的选择有误!请重新选择!","yellow"))
    print()
    welcome()

    if __name__ == '__main__':
    try:
    handler = CGIHTTPRequestHandler
    handler.cgi_directories = ['/cgi-bin', '/htbin']
    port = 8080
    server = HTTPServer(('', port), handler)
    ip=get_host_ip()
    welcome()
    print(colored("TIP5。如需退出,请按^C !","yellow"))
    print()
    server.serve_forever()


    except KeyboardInterrupt:
    print ('^C received, shutting down server')
    server.socket.close()
    2 条回复    2018-05-10 22:24:56 +08:00
    susecjh
        1
    susecjh  
       2018-05-09 09:03:41 +08:00
    uwsgi 不好用吗
    qile1
        2
    qile1  
       2018-05-10 22:24:56 +08:00 via Android
    没看懂,启用了 http 服务,打包后用不了吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   759 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:48 · PVG 05:48 · LAX 14:48 · JFK 17:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.