在 Bluehost 上安装基于 Python 的网站不起作用

在 Bluehost 上安装基于 Python 的网站不起作用

我已经用了 6 个月了,但还是无法在 Bluehost 共享服务器上响应请求。这是我最新的 python 服务器代码。

#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
from os import curdir, sep

PORT_NUMBER = 8000

#This class will handle any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
    print "Something came through 1"

    #Handler for the GET requests
    def do_GET(self):
        print "Something came through  2"
        if self.path=="/":
            self.path="/index.html"
        try:
            #Check the file extension required and
            #set the right mime type

            sendReply = False
            if self.path.endswith(".html"):
                mimetype='text/html'
                sendReply = True
            if self.path.endswith(".jpg"):
                mimetype='image/jpg'
                sendReply = True
            if self.path.endswith(".gif"):
                mimetype='image/gif'
                sendReply = True
            if self.path.endswith(".js"):
                mimetype='application/javascript'
                sendReply = True
            if self.path.endswith(".css"):
                mimetype='text/css'
                sendReply = True

            if sendReply == True:
                #Open the static file requested and send it
                f = open(curdir + sep + self.path)
                self.send_response(200)
                self.send_header('Content-type',mimetype)
                self.end_headers()
                self.wfile.write(f.read())
                f.close()
            return


        except IOError:
            self.send_error(404,'File Not Found: %s' % self.path)
            print '^C received, shutting down the web server'

try:

    #Create a web server and define the handler to manage the
    #incoming request
    server = HTTPServer(('', PORT_NUMBER), myHandler)
    print 'Started httpserver on port ' , PORT_NUMBER

    #Wait forever for incoming htto requests
    server.serve_forever()

except KeyboardInterrupt:
    print '^C received, shutting down the web server'
    server.socket.close()

我运行代码,它似乎运行良好...在服务器端使用Putty。

[email protected] [~/public_html]# python ps2.py
Started httpserver on port  8000

我在 Chrome 中启动该网站并添加此行以运行特定文件:

http://fakedomain.com:8000/

或者

它冲我吼道:

This site can’t be reached fakedomain.com.com took too long to respond.
Search Google for fakedomain com 8000
ERR_CONNECTION_TIMED_OUT

如果我使用 PORT_NUMBER = 80,它会回复:

socket.error: [Errno 13] Permission denied

如果我使用 PORT_NUMBER = 8080,它会回复:

socket.error: [Errno 98] Address already in use

正在运行的 Python 路径很好,它可以从任何地方正常启动,并且版本测试给出了以下答复:

..........[~/public_html]# python --version
Python 2.7.2

也许我需要做些其他事情来停止默认服务器的应答并允许我的服务器替换它...我没有任何线索。而且我在 WEB 上找不到任何可以帮助我在 BlueHost 上安装它的东西。我读过一些说法,除非 Django 用于 Python,否则 BlueHost 共享主机根本不起作用。我不想使用 Django...

相关内容