将网络图片上传到阿里云,使用网络流,无需下载本地
import os
import uuid
import oss2
import requests
import yaml
# 读配置文件
def read_config(file_path):
if not os.path.isfile(file_path):
print('config file not found:%s',file_path)
return False
with open(file_path, 'r', encoding='utf-8') as f:
config = yaml.load(f)
return config
def up_pic(ranks, times=3):
for v in ranks:
if v['iconlink']:
flag = 0
url = v['iconlink']
u = str(uuid.uuid1())
while times:
try:
result = upload(img_url=url, uuid=u)
except Exception as e:
times = 1
print('[upload_pic Error] %s', e)
if result:
flag = 0
v['iconlink'] = result