简体   繁体   English

AH01215:(8)执行格式错误:'/var/www/python/hello.py'的执行失败:/var/www/python/hello.py

[英]AH01215: (8) Exec format error: exec of '/var/www/python/hello.py' failed: /var/www/python/hello.py

I am trying to run python as CGI in apache server. 我试图在Apache服务器上运行python作为CGI。 Python version is 2.7.12. Python版本是2.7.12。 Here is my apache conf file 这是我的apache conf文件

<VirtualHost *:80>
   <Directory /var/www/python>
   Options +ExecCGI
   AddHandler cgi-script .cgi .py
   Order allow,deny
   Allow from all
   </Directory>
   DocumentRoot /var/www/python
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

My python script /var/www/python/hello.py looks like this 我的python脚本/var/www/python/hello.py看起来像这样

print('Content-Type: text/html; charset=utf-8\n')
print("Hello, World!")

When I access the url I get the Internal Server Error, I got the details from error.log file and it says , 当我访问url时出现内部服务器错误,我从error.log文件中获取了详细信息,它说,

[Sun Dec 11 09:53:40.694909 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282] AH01215: (8)Exec format error: exec of '/var/www/python/hello.py' failed: /var/www/python/hello.py [Sun Dec 11 09:53:40.695312 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282] End of script output before headers: hello.py [Sun Dec 11 09:53:40.694909 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282] AH01215:(8)exec格式错误:'/var/www/python/hello.py的exec '失败:/var/www/python/hello.py [Sun Dec 11 09:53:40.695312 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282]标题前面的脚本输出结束:hello。 PY

PHP scripts are still working fine on the server. PHP脚本在服务器上仍然可以正常工作。 How to fix this issue with py files ? 如何解决py文件的这个问题?

Your script needs a "shebang" line, something like 你的脚本需要一个“shebang”行,类似于

#!/usr/bin/env python

as the first line. 作为第一线。 Also, make sure the script is executable with chmod . 另外,请确保脚本可以使用chmod

You should use: 你应该使用:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print('Content-Type: text/html; charset=utf-8\n')
print("ąęśłłłóąś UTF answer")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有hello.py追溯的Python错误 - Python error with hello.py traceback Apache 尝试运行 python 脚本时出现“AH01215: (8)Exec 格式错误” - Apache "AH01215: (8)Exec format error" when attempting to run python script Flask hello.py 基本应用未运行? - Flask hello.py basic app not running? 在Android进程中运行hello.py - Running hello.py from within an Android Process 运行 make -f hello.py 时出现错误。 它说“hello.py:1: *** 缺少分隔符。停止。” - I'm getting an error when running make -f hello.py. It says " hello.py:1: *** missing separator. Stop. " C++ "Hello World" 程序调用 hello.py 到 output 字符串? - C++ "Hello World" program that calls hello.py to output the string? 我无法运行 hello.py 并得到 SyntaxError: invalid syntax - I am unable to run hello.py and get SyntaxError: invalid syntax Flask 错误'ImportError: cannot import name 'db' from 'hello' (C:\Users\admin\flask_stuff\venv\hello.py)' 当我尝试创建 SQL 数据库时 - Flask error 'ImportError: cannot import name 'db' from 'hello' (C:\Users\admin\flask_stuff\venv\hello.py)' when I try to create an SQL Database 运行dockerized Hello world python示例时执行格式错误 - Exec format Error while running dockerised Hello world python example AH01215:ImportError:没有名为PIL的模块:-从apache2配置运行时,python脚本无法识别PIL - AH01215: ImportError: No module named PIL: - python script unable to recognize PIL when running from apache2 config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM