我正处于设计阶段,也处于决定是否选择 python 作为实现软件的主要语言的阶段。任务是:
- 实现一组 Restful 网络服务
- 将 http 方法授权给特定的用户组,因为需要使用 xacml 来定义策略(或者可以是另一个标准)并使用 saml 来获取信息。交流
最佳答案
如果您的问题是可以使用哪些库来实现这些 RESTful 服务,请查看 BaseHTTPServer标准 python 库的模块。
下面的代码展示了实现一个接受 GET 请求的简单服务器是多么容易:
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
f = open(curdir + sep + self.path) #self.path has /test.html
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(f.read())
f.close()
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
def main():
try:
server = HTTPServer(('', 80), MyHandler)
print 'Welcome to the machine...'
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down server'
server.socket.close()
if __name__ == '__main__':
main()
当然,代码不是我自己的,我自己找的here .
关于python - Python 中的授权 REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5964282/