我如何修复脚本标题的过早结束和没有这样的文件或目录:exec'./.py'错误

问题描述 投票:0回答:1

我确实看过类似的问题,但我的计划没有运气

这是我的计划

#!/usr/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
device_id = form.getvalue('updateDeviceId')
manufact  = form.getvalue('updateManufactureId')
polling_add = form.getvalue('updatePollingAddress')
expand  = form.getvalue('updateExpDev')
loop_control = form.getvalue('updateLoopControl')
message  = form.getvalue('updateMessage')
descriptor = form.getvalue('updateDescriptor')
long  = form.getvalue('updateLongTag')
short = form.getvalue('updateShortTag')
date  = form.getvalue('updateDate')
hardware = form.getvalue('updateHardware')
software  = form.getvalue('updateSoftware')
device = form.getvalue('updateDevice')
protocol_major  = form.getvalue('updateProtocolMajor')
master_slave = form.getvalue('updateMS')
final  = form.getvalue('updateFinal')

print("Content-type: text/html")
print("")
print("")
print("The values are")
print("")
print("")
print("
Hello %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
" % (device_id, manufact, polling_add, expand, loop_control, message, 
descriptor, long, short, date, hardware, software, device, 
protocol_major, master_slave, final))
print("")
print("")

我正在使用MAMP来运行apache服务器。我已经在.py文件上给了chmod 755 permisssion。

下面是我的httpd.conf文件

<Directory "/Applications/MAMP/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    Order allow,deny
    AddHandler cgi-script .cgi .pl .py
    Allow from all
</Directory>
python apache cgi mamp
1个回答
0
投票

问题是这个打印声明:

print("
Hello %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
" % (device_id, manufact, polling_add, expand, loop_control, message, 
descriptor, long, short, date, hardware, software, device, 
protocol_major, master_slave, final))

在Python中,triple quotes包含多行字符串:

print("""
Hello %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
""" % (device_id, manufact, polling_add, expand, loop_control, message, 
descriptor, long, short, date, hardware, software, device, 
protocol_major, master_slave, final))
© www.soinside.com 2019 - 2024. All rights reserved.