我的計算機上有2個網絡(具有互聯網的Wifi網絡,以及基於有線電纜的本地網絡),具有特定的掩碼和IP(此配置有效)。HTTP服務器Python:如何在本地測試它?
我對本地網絡的Python HTTP服務器(我的電腦上):
或者乾脆
>>> python server.py
Serving on localhost:8000
You can use this to test GET and POST methods.
"""
import SimpleHTTPServer
import SocketServer
import logging
import cgi
import sys
if len(sys.argv) > 2:
PORT = int(sys.argv[2])
I = sys.argv[1]
elif len(sys.argv) > 1:
PORT = int(sys.argv[1])
I = ""
else:
PORT = 8000
I = ""
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
print "======= GET STARTED ======="
logging.warning("======= GET STARTED =======")
logging.warning(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
print "======= POST STARTED ======="
logging.warning("======= POST STARTED =======")
logging.warning(self.headers)
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
logging.warning("======= POST VALUES =======")
for item in form.list:
logging.warning(item)
logging.warning("\n")
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
httpd = SocketServer.TCPServer(("10.0.0.2", PORT), Handler)
print "@rochacbruno Python http server version 0.1 (for testing purposes only)"
print "Serving at: http://%(interface)s:%(port)s" % dict(interface=I or "localhost", port=PORT)
httpd.serve_forever()
我只是想嘗試一下,如果這臺服務器的工作原理:從我的谷歌Chrome,我設置這個網址:10.0.0.2/?method=1234
無痕出現在Python的外殼...
所以,我的問題是:如何從我的電腦在網絡測試該服務器的Python rst(可以肯定它有效)?
我已經跑你的代碼......它史詩般的失敗,並返回我** socket.error:[Errno 10049]請求的地址是無效的在其上下文**是否我更改端口從8000到888 。 – ZF007
看到我解答它的答案。 – ZF007