作者sbrhsieh (sbr)
看板Python
标题Re: [问题] cgi上面 import MySQLdb 无法成功,但갠…
时间Sat Jul 4 20:20:57 2009
※ 引述《magicallove (小判)》之铭言:
: 我写了下面这只python程式要来获得MySQL里面的资料
: #!/usr/bin/python
: #coding:utf-8
: import MySQLdb
: conn = MySQLdb.connect(host="x.x.x.x",user="xx",passwd="xx",db="xx")
: cursor = conn.cursor()
: cursor.execute("select * from rule")
: result = cursor.fetchall()
: print "Content-Type: text/html" # HTML is following
: print # blank line, end of headers
: print "<html>"
: print "<head>"
: print "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
: print "<title> Python import MySQLdb</title>"
: print "</head>"
: print "<body>"
: for record in result:
: print record[0]
: print "</body>"
: 如果我直接在 console 里面 python sql.py的话可以正确获得资料
: 但是放到网站上面想要作成cgi来用的时候就会出现
: Internal Server Error
: The server encountered an internal error or misconfiguration and was unable
: to complete your request.
程式的 output 没有符合 HTTP protocol。
print "HTTP/1.0 200 OK"
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
print "<html>"
print "<head>"
...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.173.139.26