#!/usr/bin/python3
import cgi, os
import docx #-->>importing docx throws internal error on apache2 server while accessing the script as shown in sys log error below
print("Content-type: text/html\r\n\r\n")
print("<html><body><h1>Online Form</h1>")
form = cgi.FieldStorage()
print("<p>Upload your file: <input type = 'file' name = 'filename' /></p>")
print("<input type='submit' value='Submit' />")
print("</form></body></html>")
#User uploads draft document here
fileitem = form['filename']
if fileitem.filename:
fn = os.path.basename(fileitem.filename)
open( '/home/'+fn, 'wb').write(fileitem.file.read())
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
apache2错误日志显示没有docx模块
[2018年10月28日星期二02:20:42.040073] [cgid:error] [pid 19404:tid 139701431580416] [client 10.254.101.169:51915]在标头之前的脚本输出结尾:stack.py
回溯(最近通话最近一次):
文件
中的文件“ /var/www/stack.py”,第3行导入docx
ImportError:没有名为“ docx”的模块
但是下面的输出显示docx模块已在python3命令行中成功导入
host@ubuntu:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import docx
>>>
>>>