SSL服务器为我提供了

SSL服务器为我提供了

本文介绍了Python SSL服务器为我提供了"501不支持的方法GET".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已关注此链接使用SSL构建简单的文件服务器.

I've followed this link to build a simple file server with SSL.

from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl

httpd = HTTPServer(('localhost', 4443), BaseHTTPRequestHandler)

# openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
httpd.socket = ssl.wrap_socket (httpd.socket, keyfile="key.pem", certfile='cert.pem', server_side=True)

httpd.serve_forever()

我已经成功创建了证书,key.pemcert.pem文件路径很酷,可以使用python server.py启动服务器.我被要求输入密码,然后输入密码,然后冻结一段时间,然后似乎可以运行.

I have created a certificate successfully, key.pem and cert.pem file paths are cool and I can start the server using python server.py. I am asked for a password, enter it, then it freezes for a bit and then it seems to run.

但是,当我输入诸如https://localhost:4443/index.html之类的URL时,会得到 500种不受支持的方法GET.错误代码说明:HTTPStatus.NOT_IMPLEMENTED-服务器不支持此操作.是否需要做更多的事情才能使服务器为当前目录提供服务?到目前为止,我只是使用python -m http.server 8000(在Mac上为SimpleHTTPServer.)我使用的是Python 3.

However, when I enter some URL such as https://localhost:4443/index.html I get 500 Unsupported method GET. Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation. Do I need to do something more to make my server serve the current directory? Until now I have just used python -m http.server 8000 (SimpleHTTPServer when on Mac.) I am using Python 3.

这是一个将保留在本地的文件,因此不必担心PEM文件和服务器脚本通过它公开(如果可以的话!).我也可以接受不受信任的证书,并指示Chrome始终访问该页面.我只需要它来允许我访问相机,而不必将我的应用程序部署在具有合法证书的地方.

This is an will stay local so don't worry about the PEM files and the server script being exposed through it (if it worked!). I am also okay with the certificate being untrusted and instructed Chrome to visit the page anyway. I just need it to allow me to access camera without having to deploy my app somewhere with a legit cert.

推荐答案

来自文档:

尝试改用 SimpleHTTPRequestHandler ,例如,

httpd = socketserver.TCPServer(('localhost', 4443), SimpleHTTPRequestHandler)

这篇关于Python SSL服务器为我提供了"501不支持的方法GET".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 12:52