Python + win10 +Apache CGI 错误500的解决方法

初始报错:

Python + win10 +Apache CGI 错误500的解决方法

 

解决方法:

①脚本运行 ,改变.py文件的权限

    # 进入项目目录 

   # 引入os模块、

cd C:\xampp\cgi-bin\pythonEg        

import os

os.chmod("hello.py",755)

 

Python + win10 +Apache CGI 错误500的解决方法

 

ScriptInterpreterSource Registry是对Windows注册表项HKEY_CLASSES_ROOT进行搜索来确定CGI脚本解释器。

但是只适用于win32。

所以可以通过使用在脚本中以"#!"行指定的解释器

Python + win10 +Apache CGI 错误500的解决方法

解决办法:第一行改为自己python的安装目录。且必须占用第一行,不然还是报错500

Python + win10 +Apache CGI 错误500的解决方法

 

#!D:\anzhuang\python\python.exe

 

效果图如下:

Python + win10 +Apache CGI 错误500的解决方法

 

③新建新项目,发现无需改权限也可以打开

Python + win10 +Apache CGI 错误500的解决方法

  有一些项目却还是报错:

Python + win10 +Apache CGI 错误500的解决方法

报错原因:项目中部分代码运行错误

例如:

#!D:\anzhuang\python\python.exe



import codecs, sys

sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer)



# CGI处理模块

import cgi, cgitb

# 创建FeildStorage实例化   

# form = cgi.FeildStorage()              // 这里报错  cgi 打印出来为空,并没有FeildStorage这个方法

# # 获取数据

# site_name = form.getValue("name")

# site_url =form.getValue("url")





print ("Content-type:text/html")

print () # 空行,告诉服务器结束头部

print ('<html>')

print ('<head>')

print ('<meta charset="utf-8">')

print ('<title>菜鸟教程 CGI 测试实验</title>')

print ('</head>')

print ('<body>')

print ('<h2>get测试:</h2>')

print ("cgi:",cgi)

print ('<h3>%s官网:%s</h3>' %(site_name, site_url))

print ('</body>')

print ('</html>')

解决办法: