环境依赖参考
https://blog.csdn.net/weixin_41735238/article/details/106734060
服务端service.py
import os
import urllib
import uuid
import requests
from spyne.application import Application
from spyne.decorator import rpc
from spyne import ServiceBase, String
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server
from paddleocr import PaddleOCR, draw_ocr
file_path = 'd:/img/'
def downimg(image_url):
try:
if not os.path.exists(file_path):
os.makedirs(file_path)
filename = '{}{}{}'.format(file_path, uuid.uuid1(),'.jpg')
res = requests.get(image_url)
with open(filename, 'wb') as f:
f.write(res.content)
return filename
except Exception as e:
print(e)
return ''
def toOCR(img_path):
try:
ocr = PaddleOCR(use_angle_cls=True,use_gpu=False)
print(img_path)
result = ocr.ocr(img_path, cls=True)
return str(result)
except Exception as ex:
print(ex)
return 0
class Test(ServiceBase):
@rpc(String, _returns=String)
def get_data(self, url):
img_path=downimg(url)
post_data=toOCR(img_path)
return post_data
app = Application([Test], 'http://schemas.xmlsoap.org/soap/envelope',in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
wsgi_app = WsgiApplication(app)
if __name__ == '__main__':
server = make_server('0.0.0.0', 8088, wsgi_app )
server.serve_forever()
请求端 customer.py
# coding:utf-8
import suds
from suds.client import Client
url = "http://127.0.0.1:8088/sbcsxt/services/GetMethods?wsdl"
client = suds.client.Client(url)
result = client.service.get_data('https://pic.ntimg.cn/file/20210629/25266409_142727125104_2.jpg')
print(result)