我正在编写python文档中给出的示例代码,代码是:
from wsgiref.simple_server import make_server, demo_app
httpd = make_server('', 8000, demo_app)
print "Serving HTTP on port 8000..."
# Respond to requests until process is killed
httpd.serve_forever()
# Alternative: serve one request, then exit
httpd.handle_request()我可以通过端口8000上的localhost访问它,但是现在如果我想用"localhost:8000 username,password“传递用户名/密码,我该怎么做呢?我已经知道如何知道身份验证是否失败,但不知道如何实际接收用户名/密码以进行检查。
任何提示和提示.....
干杯,
发布于 2012-09-27 14:46:57
如果在查询字符串中传递用户名/密码,比如WSGI,那么可以在http://localhost:8000?username=x&password=y处理函数中从环境dict:environ['QUERY_STRING']中检索它们。您可以使用标准库中的urlparse.parse_qs来解析它。如果这是要投入生产的代码,我建议Joran,您至少应该使用HTTP Basic Authentication和一些身份验证中间件,如barrel。
https://stackoverflow.com/questions/12614221
复制相似问题