【问题标题】:Bluehost-Premature end of headers in python scriptBluehost-python 脚本中的标头过早结束
【发布时间】:2015-02-04 16:51:35
【问题描述】:

我有一个网站,我的网站下的 cgi-bin 文件夹中有 2 个 python cgi 脚本。现在每次它尝试加载这两个 python cgi scipts 中的任何一个时,服务器都会返回 500 错误,并且错误的过早结束臭名昭著的错误。

所以我尝试了一些新的东西。我做了一个非常简单的python cgi-script:

#!/usr/bin/python -u

print "Content-type: text/html\n\n"
print "Hello World!"

我将它命名为hello_world.py,将它与其他2 个python 脚本一起放入cgi-bin,然后运行以下链接:http://steap.co/cgi-bin/hello_world.py,它惊人地返回了“Hello World!”。

这表明我的 python 脚本有问题,但我不知道是什么。这是我的脚本:

Steap.py

#!/usr/bin/python -u
#Steam64 ID - 76561198041707719
import urllib
import cgi, cgitb
import itertools
import urllib2
import time
from datetime import datetime
from bs4 import BeautifulSoup
from flask import Flask, jsonify, render_template, redirect
import requests
import json
import xml.etree.ElementTree as ET
from xml.dom.minidom import parseString
import sys

//code goes here

print "Content-type: text/html\n\n"
print "<div id=\"phisher-users\"></br></br>"
print getFriendList(steeam)
print "</div>"
print "<div id=\"phisher-ids\" style=\"display: none;\">"
print grabPhisherIDs()
print "</div>"

现在,当服务器尝试加载此脚本时,我得到了更多信息:

Traceback (most recent call last):
  File "Steap.py", line 9, in 
    from bs4 import BeautifulSoup
ImportError: No module named bs4
[Sat Dec 06 09:58:07 2014] [error] [client 174.61.70.33] Premature end of script headers: Steap.py

为什么会这样?我在我的网站中自定义安装了python 2.7,并且我对上面所有的自定义模块(例如bs4、flask等)都使用了pip。

非常感谢任何帮助。

【问题讨论】:

  • 你可以尝试运行 pip freeze 命令,看看它显示的是 bs4 还是 BeautifulSoup。
  • @TanveerAlam 我该怎么做?
  • 只需转到命令提示符并输入pip freeze,然后按回车键。
  • @TanveerAlam 好的,我看到了 BeautifulSoup==3.2.1beautifulsoup4==4.3.2

标签: python cgi bluehost


【解决方案1】:

我同时拥有3.2.14.3.2 版本的BeautifulSoup

$pip freeze
BeautifulSoup==3.2.1
beautifulsoup4==4.3.2

你可以像这样导入 BeautifulSoup:

>>> from bs4 import BeautifulSoup
>>> from BeautifulSoup import BeautifulSoup

您可以在 Python 终端上像这样查看BeautifulSoup 的版本。

>>> import bs4
>>> bs4.__version__
'4.3.2'
>>> import BeautifulSoup
>>> BeautifulSoup.__version__
'3.2.1' 

来自 Python 文档 Porting code to BS4

针对 Beautiful Soup 3 编写的大多数代码都可以通过一个简单的更改来针对 Beautiful Soup 4。您所要做的就是更改包名称from BeautifulSoup to bs4。所以这个:

from BeautifulSoup import BeautifulSoup

变成这样:

from bs4 import BeautifulSoup

如果您收到 ImportError “No module named BeautifulSoup”,您的问题是您正在尝试运行 Beautiful Soup 3 代码,但您只有 美汤4已安装。

如果您收到ImportError “No module named bs4”,您的问题是您正在尝试运行 Beautiful Soup 4 代码,但您只有 Beautiful Soup 3 已安装。

【讨论】:

  • 我现在收到错误:Traceback (most recent call last): File "Steap.py", line 9, in from BeautifulSoup import BeautifulSoup ImportError: No module named BeautifulSoup
  • 那你应该试试import BeautifulSoup or import beautifulsoup4 or import bs4 看看哪个最适合你。
  • 问题是我所有的自定义模块都有导入错误,不仅仅是beautifulsoup。
猜你喜欢
  • 1970-01-01
  • 2013-01-16
  • 2012-12-03
  • 2014-06-03
  • 2012-09-23
  • 1970-01-01
  • 1970-01-01
  • 2011-11-01
  • 2012-06-25
相关资源
最近更新 更多