Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

Python进行,七牛多文件压缩(mkzip) 返回结果为 404,Document not found

用Python进行七牛多文件处理(mkzip),一直报404的错,索引文件没有问题,可以访问,索引文件内的图片地址也是可以访问的,不知道是哪个文件找不到
参考的七牛相关文档:
https://developer.qiniu.com/k...
https://developer.qiniu.com/d...

from qiniu import Auth, PersistentFop, urlsafe_base64_encode

access_key = '....'
secret_key = '....'
q = Auth(access_key, secret_key)

bucket = 'hera'
key = 'mkzip-index_2.txt'
fops = 'mkzip/4/'

saveas_key = urlsafe_base64_encode(bucket + ':' + "xlz_mkzip4.zip")
fops = fops+'|saveas/'+saveas_key

pfop = PersistentFop(q, bucket)
ops = []
ops.append(fops)
ret, info = pfop.execute(key, ops, 1)
print("ret:   ", ret)
print("info:   ", info)
assert ret['persistentId'] is not None

打印结果

ret:    None
info:    _ResponseInfo__response:<Response [404]>, exception:None, status_code:404, text_body:{"error":"Document not found"}, req_id:wpUAAABWbvpfniQW, x_log:X-Log, error:Document not found

索引文件:
https://heras.igengmei.com/mk...

索引文件内容生成过程:

from qiniu import urlsafe_base64_encode
images = ["https://heras.igengmei.com/2020/07/23/0fcd8a243b", "https://heras.igengmei.com/2020/07/23/e8f134ef12", "https://heras.igengmei.com/2020/07/24/d9d4f234a5"]
for i in images:
    print('/url/' + urlsafe_base64_encode(i))
生成结果:
/url/aHR0cHM6Ly9oZXJhcy5pZ2VuZ21laS5jb20vMjAyMC8wNy8yMy8wZmNkOGEyNDNi
/url/aHR0cHM6Ly9oZXJhcy5pZ2VuZ21laS5jb20vMjAyMC8wNy8yMy9lOGYxMzRlZjEy
/url/aHR0cHM6Ly9oZXJhcy5pZ2VuZ21laS5jb20vMjAyMC8wNy8yNC9kOWQ0ZjIzNGE1

确定空间名没有问题,
尝试加管道也没用


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

任务的id提供下呢,或者试下这个demo

# -*- coding: utf-8 -*-
# flake8: noqa
#DOCUMENT https://developer.qiniu.com/dora/manual/1667/mkzip#2
from qiniu import Auth,http, urlsafe_base64_encode
  
access_key = 'YOUR_ACCESS_KEY'
secret_key = 'YOUR_SECRECT_KEY'
q = Auth(access_key, secret_key)
 
url = 'http://api.qiniu.com/pfop/'
 
fops = "mkzip/4"
saveas_key = urlsafe_base64_encode('bucket_name:save.zip') # 转码后的空间:文件名
fops = fops + '|saveas/' + saveas_key
 
body = { "fops": fops, 'bucket': 'bucket_name', 'key': 'index.txt'} # 索引文件所在空间及索引文件名
 
ret, info = http._post_with_auth(url=url, data=body, auth=q)
print(info)
assert ret['persistentId']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...