python - (8)Exec格式错误: exec of ' ' failed - CentOS

标签 python linux

我使用的是 Backspace 中安装了 LAMP 的 CentOS 虚拟机。 我有一个 python 脚本,想从 CGI-BIN 运行。 我已在浏览器上浏览到该路径,但收到 500 服务器错误。 当然,这是我第一次使用 CentOS 和 python,但我了解得很好。但这确实让我着迷。 我收到此错误:

[Tue Nov 04 12:46:07 2014] [error] [client 86.2.110.133] (8)Exec format error: exec of '/var/www/cgi-bin/payment-test.cgi' failed
[Tue Nov 04 12:46:07 2014] [error] [client 86.2.110.133] Premature end of script headers: payment-test.cgi

这是我的脚本:

import sys
import json
import cgi
import cgitb
import stripe

#2
cgitb.enable()

print 'Content-Type: text/json'
print

#3
stripe.api_key = ''
#4
json_data = sys.stdin.read()
json_dict = json.loads(json_data)

#5
stripeAmount = json_dict['stripeAmount']
stripeCurrency = json_dict['stripeCurrency']
stripeToken = json_dict['stripeToken']
stripeDescription = json_dict['stripeDescription']

#6
json_response = stripe.Charge.create(amount=stripeAmount, currency=stripeCurrency, card=stripeToken, description=stripeDescription)

print json_response

是因为没有 header 指向我的 Python 文件吗?如果有的话他们在哪里? 请帮助我,我很迷失。

谢谢

最佳答案

您需要一个 hashbang line在顶部。

#!/usr/bin/env python

import sys
import json
import cgi
...

关于python - (8)Exec格式错误: exec of ' ' failed - CentOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26738221/

相关文章:

linux - 只打印命令结果的一部分

jquery - 如何在客户端和服务器端使用验证规则?

python - django 创建多种类型用户的最佳方法

ruby-on-rails - Redmine 需要 bundler 1.5.0 或更高版本

java - Linux Bootstrap 消耗内存

python - 没有名为 'virtualenvwrapper' 的模块

python - Sympy 用平方倍数简化不等式

python - 将不同数据类型的哈希值放在一起?

python - 在 Python 中解构赋值顺序

linux - 如何删除 bash 脚本中的多个字符?