httpd.serve_forever不保持服务器运行

时间:2017-10-14 03:11:14

标签: python http socketserver

我有一台HTTP服务器,每次添加功能或添加打印机制时 它给我一个错误。例如,在这种情况下,我正在尝试使用管理控制台,并且我转到服务器的URL,除了无法在Google Chrome中连接之外什么都没有。

它只接受http.serve_forever()吗?或者在控制台启动后可以拥有管理控制台。因为这就是我想要做的。但是没有URL来查看HTTP Server。含义httpd.serve_forever()在我的视图中无法正常运行。有没有什么办法解决这一问题?

import http.server
import socketserver
import os
#Create Login System at (10:30)

# Create Management Console
def Management():
commands = ["info", "exit", "openurl","restart","login"]
usr_input = input("> ")
if usr_input == commands[0]:
    print("The Port Running for this server is: ", PORT)
    print("The URL of the server is: ", HOST, PORT)

if usr_input == commands[1]:
    exit_verify = input("Are you sure?: Y/N")
    if exit_verify == "Y" or "y":
        exit()
    else:
        print("Invalid Response...")
        Management()

    if exit_verify == "N" or "n":
        Management()

if usr_input == commands[2]:
    URL = "start"
    URL = url+Address
    os.system(URL)
# If cmd opens close window after opening URL

else:
    Management()

if usr_input == commands[3]:
# Note to Readme as the server needs to be stored on "C:\" Directory
    os.system("start F:\Python36\httpserver.py")
    os.system("exit")
    exit()
else: 
    Management()





HOST = input("Your IP Address: ")
PORT = 8080

Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer((HOST, PORT), Handler)
Management()
httpd.serve_forever()

0 个答案:

没有答案