Python SSL服务器为我提供了"501不支持的方法GET".

编程入门 行业动态 更新时间:2024-10-24 08:32:23
本文介绍了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.pem和cert.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.

但是,当我输入诸如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 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.

推荐答案

来自文档:

http.server.BaseHTTPRequestHandler类(请求,客户端地址,服务器)

class http.server.BaseHTTPRequestHandler(request, client_address, server)

此类用于处理到达服务器的HTTP请求.就其本身而言,它不能响应任何实际的HTTP请求.必须将其子类化以处理每种请求方法(例如GET或POST).

This class is used to handle the HTTP requests that arrive at the server. By itself, it cannot respond to any actual HTTP requests; it must be subclassed to handle each request method (e.g. GET or POST).

尝试改用 SimpleHTTPRequestHandler ,例如,

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

更多推荐

Python SSL服务器为我提供了"501不支持的方法GET".

本文发布于:2023-10-29 03:32:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538600.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为我   不支持   服务器   方法   SSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!