ppv5 / post.py
dlxj
https 改造
db719a3
Raw
History Blame Contribute Delete
1.44 kB
# .venv/Scripts/python post.py
import requests
import base64
import json
import os
def test_ppocr():
# Configuration
# url = "http://127.0.0.1:8889/ppocr"
url = "https://127.0.0.1:9346/ppocrv6"
image_path = r"data/SWX0005_00000_00001.webp"
# Check if image exists
if not os.path.exists(image_path):
print(f"Error: Image file not found at {image_path}")
return
try:
# Read and encode image
with open(image_path, "rb") as image_file:
base64_str = base64.b64encode(image_file.read()).decode('utf-8')
# Prepare payload
payload = {
"img": base64_str,
"reverse": True # 逆序结果行 古籍可能需要逆序
}
headers = {
"Content-Type": "application/json"
}
# Send request
print(f"Sending POST request to {url}...")
response = requests.post(url, json=payload, headers=headers, verify=False)
# Print result
print(f"Status Code: {response.status_code}")
try:
print("Response JSON:")
print(json.dumps(response.json(), indent=4, ensure_ascii=False))
except json.JSONDecodeError:
print("Response Text:")
print(response.text)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
test_ppocr()