convert_test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import base64
  2. import json
  3. import os
  4. import sys
  5. sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../")
  6. from format_convert.utils import get_platform, request_post
  7. def test_one(p, from_remote=False):
  8. with open(p, "rb") as f:
  9. file_bytes = f.read()
  10. file_base64 = base64.b64encode(file_bytes)
  11. data = {"file": file_base64, "type": p.split(".")[-1], "filemd5": 100}
  12. if from_remote:
  13. _url = 'http://172.20.1.251:15010/convert'
  14. # _url = 'http://192.168.2.102:15010/convert'
  15. # _url = 'http://172.16.160.65:15010/convert'
  16. result = json.loads(request_post(_url, data, time_out=10000))
  17. else:
  18. print("only support remote!")
  19. print("result_text", result.get("result_text")[0][:20])
  20. print("is_success", result.get("is_success"))
  21. if __name__ == '__main__':
  22. if get_platform() == "Windows":
  23. # file_path = "C:/Users/Administrator/Desktop/error7.jpg"
  24. # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_Interface/20210609202634853485.xlsx"
  25. # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_ODPS/1624325845476.pdf"
  26. file_path = "C:/Users/Administrator/Downloads/1650967920520.pdf"
  27. else:
  28. file_path = "test1.doc"
  29. test_one(file_path, from_remote=True)