I have a python script save.cgi in public_html/menuProject/ on a server example.com
I'm able to access the script from the browser by calling example.com/menuProject/save.cgi?xml=Hello
and display "hello", but when I try to write to a file, it gives me 500 internal server error.
import os, sys
import cgi
print "Content-Type: text/plain;charset=utf-8"
print
form = cgi.FieldStorage()
xml = form.getvalue("xml")
resultFile = "feed.xml"
print "hello"
with open(resultFile, "w") as f:
f.write(xml)
Both save.cgi
and feed.xml
are in the same folder public_html/menuProject/
and the file permissions for menuProject
and all files is : -rwxrwxrwx
.
Can you please help me figure out why it still is giving me 500 internal server error?
UPDATE: Thanks to @Jon Clements
I did a : print sys.version
and found out that the webserver version was 2.4 while the code was in 2.6
Got it working by removing the with
.
import os, sys
import cgi
print "Content-Type: text/plain;charset=utf-8"
print
form = cgi.FieldStorage()
xml = form.getvalue("xml")
resultFile = "feed.xml"
print "hello"
f = open(resultFile, "w")
f.write(xml)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.