loit 发表于 2015-12-15 13:39:20

python CGIHTTPServer不能解释脚本

最近刚学习python CGI,然后测试了下:



[*]#/usr/bin/python
#coding=utf-8

[*]import MySQLdb

[*]print 'Content-Type: text/html'
[*]print
[*]print 'read the table testmysql'
[*]print
[*]print '''NAME

[*]
'''

[*]conn=MySQLdb.connect(user='root',passwd='***',db='testmysql')
[*]cur=conn.cursor()
[*]cur.execute("select * from a")
[*]for i in cur.fetchall():
[*]    print '
[*]%s' % i[1]
[*]
[*]
[*]print '
'

[*]print ''
[*]conn.commit()
[*]conn.close()
[*]
在当前目录下启动python -m CGIHTTPServer 8000,结果调用时却显示脚本内容,根本没有进行解释,然后出现代码OSError: Exec format error,网上查找相应的资料,然后找到python CGIHTTPServer的一些问题看到#!/usr/bin/python,就在此时找问题的所在,更新之后就成功显示数据库中查询.这篇文章上也有windows下出现3个头字节.可以去看看...还有一个问题就是权限和目录,权限需要进行调整,否则不能正常执行.目录,python脚本文件需要放在cgi-bin/htbin目录下.
页: [1]
查看完整版本: python CGIHTTPServer不能解释脚本