Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用web.py创建下载命令_Python_Web.py - Fatal编程技术网

Python 使用web.py创建下载命令

Python 使用web.py创建下载命令,python,web.py,Python,Web.py,我在web.py中创建了一个新文件,并尝试创建一个下载命令 我创建了一个: import web urls = ( '/', 'index', '/download', 'Download' ) class index: def GET(self): return "Hello, world!" class Download: def GET(self): path = 'http:\\localhost:8080\C:

我在web.py中创建了一个新文件,并尝试创建一个下载命令

我创建了一个:

import web

urls = (
    '/', 'index',
    '/download', 'Download'
)

class index:
    def GET(self):
        return "Hello, world!"

class Download:
    def GET(self):
           path = 'http:\\localhost:8080\C:\11\229077_6482396906_558_n.jpg' 
           web.header('Content-Disposition', 'attachment; filename="fname.ext"')
           web.header('Content-type','images/jpeg')
           web.header('Content-transfer-encoding','binary') 
           return open(path, 'rb').read()

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
我有两个主要问题:

  • 当我进入
    http://localhost:8080/download
    ,它给我500个内部服务器错误。为什么?

  • 我无法选择要下载的文件(只需手动更改路径参数)。我如何给出这个函数的外部参数

  • 500是一般错误代码,因此很难诊断。在设置代码时,我会检查浏览器中的URI,以确定服务器是否正常运行。错误代码的完整列表-

  • 您只能找到具有指向它们的链接的文件。例如,请参见


  • 2.例如,将以下内容添加到代码中:

    filename = web.input().file
    
    因此,在输入链接时,它将返回所需的文件名:

    yoursite.tld/downloads?file=FILENAME
    

    请在此处阅读有关此主题的更多信息:

    检查您试图从中读取文件的路径。它就是找不到那个文件。