我正在尝试通过在Html页面上输入并运行python脚本来编写XML文档。
HTML:
<html>
<head>
</head>
<body>
<form action="/cgi-bin/dscr.cgi " method="post">
serverID:<input type= "text" name="field1" id="textbox" /> </br>
name:<input type= "text" name="field2" id="textbox2" /> </br>
host:<input type= "text" name="field3" id="textbox3" /> </br>
port:<input type= "text" name="field4" id="textbox4" /> </br>
proto:<input type= "text" name="field5" id="textbo5x" /> </br>
user:<input type= "text" name="field6" id="textbox6" /> </br>
password:<input type= "text" name="field7" id="textbox7" /> </br>
key:<input type= "text" name="field8" id="textbox8" /> </br>
companyName:<input type= "text" name="field9" id="textbox9" /> </br>
officeAddress:<input type= "text" name="field10" id="textbox10" /> </br>
state:<input type= "text" name="field11" id="textbox11" /> </br>
country:<input type= "text" name="field12" id="textbox12" /> </br>
lAdmin:<input type= "text" name="field13" id="textbox13" /> </br>
phone:<input type= "text" name="field14" id="textbox14" /> </br>
mobile:<input type= "text" name="field15" id="textbox15" /> </br>
email:<input type= "text" name="field16" id="textbox16" /> </br>
designation:<input type= "text" name="field17" id="textbox17" /> </br>
reportingMgr:<input type= "text" name="field18" id="textbox18" /> </br>
<input type="submit" id="btn" value ="send" />
</form>
</body>
</html>
这是被调用的python脚本:
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
#
#author__ = "Devanshu Misra"
# __copyright__ = "Copyright 2017, ACPL Systems Pvt. Ltd."
# __license__ = "proprietary"
# __version__ = "1.0.1"
# __status__ = "Under Development"
import cgi, cgitb
import xml.etree.ElementTree as et
import os
base_path = os.path.dirname(os.path.realpath(__file__))
xml_file = os.path.join(base_path, "company.xml")
form = cgi.FieldStorage()
serverId = form.getvalue("field1")
name = form.getvalue("field2")
host = form.getvalue("field3")
port = form.getvalue("field4")
proto = form.getvalue("field5")
user = form.getvalue("field6")
password = form.getvalue("field7")
key = form.getvalue("field8")
company = form.getvalue("field9")
officeAddr = form.getvalue("field10")
state = form.getvalue("field11")
country = form.getvalue("field12")
ladmin = form.getvalue("field13")
phone = form.getvalue("field14")
mobile = form.getvalue("field15")
email = form.getvalue("field16")
designation = form.getvalue("field17")
reportingMgr = form.getvalue("field18")
tree = et.parse(xml_file)
root = tree.getroot()
new_server = et.SubElement(root, "server",
id = str(serverId))
new_name = et.SubElement(new_server, "name")
new_host = et.SubElement(new_server, "host")
new_port = et.SubElement(new_server, "port")
new_proto = et.SubElement(new_server, "proto")
new_user = et.SubElement(new_server, "user")
new_password = et.SubElement(new_server, "password")
new_key = et.SubElement(new_server, "key")
new_company_name = et.SubElement(new_server, "companyName")
new_address = et.SubElement(new_server, "address")
new_office_address = et.SubElement(new_address, "officeAddress")
new_state = et.SubElement(new_address, "state")
new_country = et.SubElement(new_address, "country")
new_contacts = et.SubElement(new_server, "contacts")
new_ladmin = et.SubElement(new_contacts, "ladmin")
new_phone = et.SubElement(new_contacts, "phone")
new_mobile = et.SubElement(new_contacts, "mobile")
new_email = et.SubElement(new_contacts, "email")
new_designation = et.SubElement(new_contacts, "designation")
new_reportingManager = et.SubElement(new_contacts, "reportingManager")
new_name.text = name
new_host.text = host
new_port.text = port
new_proto.text = proto
new_user.text = user
new_password.text = password
new_key.text = key
new_company_name.text = company
new_office_address.text = officeAddr
new_state.text = state
new_country.text = country
new_ladmin.text = ladmin
new_phone.text = phone
new_mobile.text = mobile
new_email.text = email
new_designation.text = designation
new_reportingManager.text = reportingMgr
tree.write(xml_file)
这是我的XML文件的格式:
<data>
<server id="bvcbv">
<name>c</name>
<host>bvc</host>
<port>bvc</port>
<proto>bc</proto>
<user>bv</user>
<password>cb</password>
<key>vcb</key>
<companyName>vc</companyName>
<address>
<officeAddress>bc</officeAddress>
<state>bvc</state>
<country>bvc</country>
</address>
<contacts>
<ladmin>bvc</ladmin>
<phone>bvc</phone>
<mobile>bvc</mobile>
<email>bv</email>
<designation>cbv</designation>
<reportingManager>cb</reportingManager>
</contacts>
</server>
</data>
执行时,我收到内部服务器错误,但是当我检查python脚本时没有回溯调用,并且所有标记都是用XML编写的,但没有用户输入的值。为什么会发生这种情况,我该如何解决这个问题?