Files
enginex-mlu370-translation/test.py
2025-09-15 14:42:26 +08:00

32 lines
676 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
url = "http://127.0.0.1:10078/v1/translate"
body = [
{"Text": "生活就像一块巧克力"},
{"Text": "你来自哪里"},
{"Text": "你吃饭了吗"},
]
headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}
try:
response = requests.post(
url,
json=body,
headers=headers
)
if response.status_code == 200:
print("Succeed!")
print("Response:", response.json())
else:
print(f"Failedcode: {response.status_code}")
print("Error detail:", response.text)
except requests.exceptions.RequestException as e:
print("request error:", str(e))