Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create an one-time web Service by python

Shulou Source: shulou.com Published: 2022-06-01 04:27:25 10月05日 Update

This article mainly introduces python how to create a web service, the article is very detailed, has a certain reference value, interested friends must read it!

Create a disposable, fast, small web service

Sometimes we need to do some simple, basic RPC-like interaction between two machines or services. We want to use the B program to call a method in the A program in a simple way-sometimes on another machine. For internal use only.

I do not encourage the use of the methods described here in non-internal, one-off programming. We can use a protocol called XML-RPC (corresponding to this Python library) to do this.

Here is an example of using the SimpleXMLRPCServer module to build a fast, small file reading server:

From SimpleXMLRPCServer import SimpleXMLRPCServer def file_reader (file_name): with open (file_name, r) as f: return f.read () server = SimpleXMLRPCServer ((localhost, 8000)) server.register_introspection_functions () server.register_function (file_reader) server.serve_forever ()

Client

Import xmlrpclibproxy = xmlrpclib.ServerProxy (http://localhost:8000/) proxy.file_reader (/ tmp/secret.txt)

This gives us a remote file reading tool with no external dependencies and only a few lines of code (of course, there are no security measures, so you can only do this at home).

The above is all the content of the article "how to create a web service for python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Services build one one-time content files methods machines programs articles simplicity security between things code value examples interests only basics customers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Huawei NVidia Shulou Technology