Files
ocr/test009.py
2025-08-14 16:04:59 +08:00

37 lines
1.1 KiB
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 uuid
import json
from obs import ObsClient
import traceback
from openai import OpenAI
ak = "HZDE30KAN5C5OLJ9JCCF"
sk = "3QO1IJNRrFZyER1e1NBBu4qSyqDfZ8Xup0YPzDFW"
client = OpenAI(
# 若没有配置环境变量请用百炼API Key将下行替换为api_key="sk-xxx",
api_key="sk-01d13a39e09844038322108ecdbd1bbc",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
server = "https://obs.cn-north-1.myhuaweicloud.com"
obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)
try:
bucketName = "dsideal"
# 对象名,即上传后的文件名
objectKey = str(uuid.uuid4()) + ".jpg"
# 待上传文件的完整路径如aa/bb.txt
file_path = "./img04.jpg"
# 文件上传
resp = obsClient.putFile(bucketName, objectKey, file_path)
# 返回码为2xx时接口调用成功否则接口调用失败
if resp.status < 300:
print('Put File Succeeded')
print('文件地址:', resp.body.objectUrl)
else:
print('Put File Failed')
except:
print('Put File Failed')
print(traceback.format_exc())