echodict/ppv5
0220
1
2# .venv/Scripts/python post.py
3
4import requests
5import base64
6import json
7import os
8
9def test_ppocr():
10 # Configuration
11 # url = "http://127.0.0.1:8889/ppocr"
12 url = "https://127.0.0.1:9346/ppocrv6"
13 image_path = r"data/SWX0005_00000_00001.webp"
14
15 # Check if image exists
16 if not os.path.exists(image_path):
17 print(f"Error: Image file not found at {image_path}")
18 return
19
20 try:
21 # Read and encode image
22 with open(image_path, "rb") as image_file:
23 base64_str = base64.b64encode(image_file.read()).decode('utf-8')
24
25 # Prepare payload
26 payload = {
27 "img": base64_str,
28 "reverse": True # 逆序结果行 古籍可能需要逆序
29 }
30 headers = {
31 "Content-Type": "application/json"
32 }
33
34 # Send request
35 print(f"Sending POST request to {url}...")
36 response = requests.post(url, json=payload, headers=headers, verify=False)
37
38 # Print result
39 print(f"Status Code: {response.status_code}")
40 try:
41 print("Response JSON:")
42 print(json.dumps(response.json(), indent=4, ensure_ascii=False))
43 except json.JSONDecodeError:
44 print("Response Text:")
45 print(response.text)
46
47 except Exception as e:
48 print(f"An error occurred: {e}")
49
50if __name__ == "__main__":
51 test_ppocr()
52 