Start HTTP/HTTPS server, python -m SimpleHTTPServer

匿名 (未验证) 提交于 2019-12-03 09:05:37

问题:

I am trying to start HTTPS server on my localhost, but getting below error. I have opened cmd as an administrator.

C:\Windows\system32>python -m SimpleHTTPServer Traceback (most recent call last):   File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main     "__main__", fname, loader, pkg_name)   File "C:\Python27\lib\runpy.py", line 72, in _run_code     exec code in run_globals   File "C:\Python27\lib\SimpleHTTPServer.py", line 224, in <module>     test()   File "C:\Python27\lib\SimpleHTTPServer.py", line 220, in test     BaseHTTPServer.test(HandlerClass, ServerClass)   File "C:\Python27\lib\BaseHTTPServer.py", line 595, in test     httpd = ServerClass(server_address, HandlerClass)   File "C:\Python27\lib\SocketServer.py", line 419, in __init__     self.server_bind()   File "C:\Python27\lib\BaseHTTPServer.py", line 108, in server_bind     SocketServer.TCPServer.server_bind(self)   File "C:\Python27\lib\SocketServer.py", line 430, in server_bind     self.socket.bind(self.server_address)   File "C:\Python27\lib\socket.py", line 224, in meth     return getattr(self._sock,name)(*args) socket.error: [Errno 10013] An attempt was made to access a socket in a way forb idden by its access permissions 

回答1:

Your windows firewall may block python from listening. Additionaly, try adding a different port number higher than 1024 to the command line and see if it helps.



回答2:

I was not able to start since some service is already running on 8000, I was able to successfully start the service on another port 2000

C:\>python -m SimpleHTTPServer 2000 Serving HTTP on 0.0.0.0 port 2000 .. 

One can get the PID/status for port 8000 by netstat -ano

C:\>netstat -ano  Active Connections    Proto  Local Address          Foreign Address        State           PID   TCP    0.0.0.0:912            0.0.0.0:0              LISTENING       2544   TCP    0.0.0.0:8000           0.0.0.0:0              LISTENING       4   TCP    0.0.0.0:19781          0.0.0.0:0              LISTENING       3100 

shows PID 4 which is a system process.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!