Python 2.7 XMLRPC client 範例程式碼:
#!/usr/bin/env python # -*- coding: UTF-8 -*- from __future__ import print_function import shutil from xmlrpclib import Binary from xmlrpclib import Server # XML RPC server ip & port SERVER_IP = '59.127.82.215' SERVER_PORT = 8000 # image file dir IMG_DIR = 'img_jpg' def main(): # create OCR object serviceIP = 'http://%s:%s' % (SERVER_IP, SERVER_PORT) obj = Server(serviceIP) # make img zip file and convert it to binary data for upload shutil.make_archive(IMG_DIR, 'zip', IMG_DIR) img_fn = IMG_DIR + '.zip' with open(img_fn, "rb") as handle: binary_data = Binary(handle.read()) # call OCR function rst_lst = obj.exe(binary_data) # rst_lst = [ ('A18.jpg', u'里'), ... ] # print ocr result for k in rst_lst: print(k[0], k[1]) if __name__ == '__main__': main() |