简体   繁体   English

无法使用python cgi脚本引发“文件下载”对话框

[英]unable to Raise a “File Download” Dialog Box using python cgi script

In my pursuit to pop up a download box in the client window(for sqlite3.db file). 在我的追求下,在客户端窗口中弹出一个下载框(用于sqlite3.db文件)。 I wrote this code: 我写了这段代码:

#!/usr/bin/env python
import os
# HTTP Header
print "Content-Type:application/octet-stream; name=\"sqlite3.db\"\r\n";
print "Content-Disposition: attachment; filename=\"sqlite3.db\"\r\n\n";

# Actual File Content will go hear.
fo = open("sqlite3.db", "rb")

str = fo.read();
print str

# Close opend file
fo.close()

I am experiencing an error(copied from error logs) mentioning "IOError: [Errno 2] No such file or directory: 'sqlite3.db' " 我遇到一个错误(从错误日志中复制),其中提到“ IOError:[Errno 2]没有这样的文件或目录:'sqlite3.db'”

I have also pasted both the python.py and sqlite3.db in /var/www/cgi-bin/ and i have assigned 0755 chmod to both. 我也将python.py和sqlite3.db都粘贴到了/ var / www / cgi-bin /中,并且我给两者都分配了0755 chmod。

I have checked by configuration by printing Hello world script. 我已经通过打印Hello world脚本进行了配置检查。

Any idea what what is my mistake? 知道我的错误是什么吗? i am still confused where should i give the path to the downloadable file? 我仍然感到困惑,我应该在哪里提供可下载文件的路径?

HTTP header terminate early. HTTP标头提早终止。 ( print itself write newline) print自己写换行符)

print "Content-Type:application/octet-stream; name=\"sqlite3.db\"\r\n";
print "Content-Disposition: attachment; filename=\"sqlite3.db\"\r\n\n";

Abobe lines should be: Abobe行应为:

print 'Content-Type:application/octet-stream; name="sqlite3.db'
print 'Content-Disposition: attachment; filename="sqlite3.db'
print

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM