base64_sample.py 460 B

123456789101112131415161718
  1. import base64
  2. import requests
  3. local_img_path = './test.png'
  4. with open(local_img_path, 'rb') as f:
  5. base64_bytes = base64.encodebytes(f.read())
  6. # or
  7. # base64.encodebytes(f.read())
  8. api_url = 'http://localhost:5000/api/ocr_dec'
  9. # or
  10. # api_url = 'http://0.0.0.0:5000/api/ocr_dec'
  11. data = {
  12. 'img_base64': base64_bytes
  13. # or
  14. # 'img_base64': base64_bytes.decode()
  15. }
  16. response = requests.post(api_url, data=data)
  17. json = response.json()
  18. print(json)