Ejemplo n.º 1
0
def qiniu_bucket_swith(bucket_name, private):
    """
    bucket_name: 存储空间名
    private: 0 公开;1 私有 ,str类型
    """
    # 构建鉴权对象
    q = Auth(qiniu_ak, qiniu_sk)
    # 初始化BucketManager
    bucket = BucketManager(q)
    # 你要测试的空间, 并且这个key在你空间中存在
    ret, info = bucket.bucket_info(bucket_name)
    if ret['private'] == private:
        logger.info(
            f"无需操作:{bucket_name} 当前为{'公开' if private == 0 else '私有'}空间")
        return True
    ret, info = bucket.change_bucket_permission(bucket_name, private)
    if info.status_code == 200:
        logger.info(
            f"操作成功:{bucket_name}已修改为{'公开' if private == 0 else '私有'}空间")
        return True
    else:
        logger.info(f"操作失败")
        return False
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth
from qiniu import BucketManager

# 需要填写七牛账号的 公钥和私钥
access_key = '<access_key>'
secret_key = '<secret_key>'

# 空间名
bucket_name = ""

# private 参数必须是str类型,0表示公有空间,1表示私有空间
private = "0"

q = Auth(access_key, secret_key)

bucket = BucketManager(q)

ret, info = bucket.change_bucket_permission(bucket_name, private)
print(info)