Go语言 使用上行链路Python创建新的存储桶

crcmnpdw  于 2022-12-07  发布在  Go
关注(0)|答案(1)|浏览(103)

我正在尝试用upplink-python创建一个新的storj bucket有人知道这个错误吗?
谢谢你

class Storage:

def __init__(self, api_key: str, satellite: str, passphrase: str, email: str):
    """
        account Storj
    """
    self.api_key = api_key
    self.satellite = satellite
    self.email = email
    self.passphrase = passphrase
    self.uplink = Uplink()
    self.config = Config()
    self.access = self.uplink.config_request_access_with_passphrase(self.config,
                                                                    self.satellite,
                                                                    self.api_key,
                                                                    self.passphrase)
    self.project = self.access.open_project() <-- open the project

def create_bucket(self, mybucket: str):
    """
     Create un bucket and ingnores the error if it already exist
    """
    print(mybucket)
    self.project.ensure_bucket(mybucket)

def get_bucket(self, mybucket: str):
    """
     verify bucket
    """
    print(mybucket)
    return self.project.stat_bucket(mybucket)

def close(self):
    self.project.close()

storage = Storage(api_key="zzz", satellite=".storj.io:7777", passphrase="passtest", mail="bucket@bucket.com")

验证旧桶

storage.get_bucket("demo01") # it's works

创建新存储桶

storage.create_bucket("Hello") # internal error

输出:
文件“../test/uplink/lib/python3.9/site-packages/uplink_python/project.py“,第121行,在确保_存储桶引发_存储异常(存储桶_结果.错误.内容.代码,uplink_python.错误.内部错误:'内部错误'
第121行

def ensure_bucket(self, bucket_name: str):
    """
    function ensures that a bucket exists or creates a new one.

    When bucket already exists it returns a valid Bucket and no error

    Parameters
    ----------
    bucket_name : str

    Returns
    -------
    Bucket
    """

    #
    # declare types of arguments and response of the corresponding golang function
    self.uplink.m_libuplink.uplink_ensure_bucket.argtypes = [ctypes.POINTER(_ProjectStruct),
                                                             ctypes.c_char_p]
    self.uplink.m_libuplink.uplink_ensure_bucket.restype = _BucketResult
    #
    # prepare the input for the function
    bucket_name_ptr = ctypes.c_char_p(bucket_name.encode('utf-8'))

    # open bucket if doesn't exist by calling the exported golang function
    bucket_result = self.uplink.m_libuplink.uplink_ensure_bucket(self.project, bucket_name_ptr)
    #
    # if error occurred
    if bool(bucket_result.error):
        raise _storj_exception(bucket_result.error.contents.code,
                               bucket_result.error.contents.message.decode("utf-8"))
    return self.uplink.bucket_from_result(bucket_result.bucket)

“内部错误”消息来自“raise _storj_exception.”。
add:使用Web界面创建新存储桶时没有错误
参考https://storj-thirdparty.github.io/uplink-python/#/library?id=ensure_bucketbucket_name
https://github.com/storj/uplink/blob/8da069b86063ee9671cc85cc44eaa6b8baf84b58/bucket.go#L97

qjp7pelc

qjp7pelc1#

已解决:存储桶名称中的大写字母导致内部错误...
取代了

storage.create_bucket("Hello")

storage.create_bucket("hello")

:)
编辑:这就是为什么:https://forum.storj.io/t/bucket-name-uppercase/20554/2?u=mike1

相关问题