使用uplink-Python创建一个新的storj存储桶。

huangapple go评论94阅读模式
英文:

Create a new storj bucket with uplink-Python

问题

我正在尝试使用uplink-python创建一个新的storj存储桶,有人知道这个错误吗?

谢谢

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() <-- 打开项目

    def create_bucket(self, mybucket: str):
        """
         创建一个存储桶,如果已存在则忽略错误
        """
        print(mybucket)
        self.project.ensure_bucket(mybucket)

    def get_bucket(self, mybucket: str):
        """
         验证存储桶
        """
        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") # 运行正常

创建一个新的存储桶

storage.create_bucket("Hello") # 内部错误


输出

>  File "../test/uplink/lib/python3.9/site-packages/uplink_python/project.py", line 121, in ensure_bucket
    raise _storj_exception(bucket_result.error.contents.code,
uplink_python.errors.InternalError: 'internal error'


121
    def ensure_bucket(self, bucket_name: str):
        """
        确保存储桶存在或创建一个新的存储桶。

        当存储桶已存在时,返回一个有效的存储桶而不报错

        参数
        ----------
        bucket_name : str

        返回
        -------
        Bucket
        """

        #
        # 声明相应的golang函数的参数和返回值类型
        self.uplink.m_libuplink.uplink_ensure_bucket.argtypes = [ctypes.POINTER(_ProjectStruct),
                                                                 ctypes.c_char_p]
        self.uplink.m_libuplink.uplink_ensure_bucket.restype = _BucketResult
        #
        # 准备函数的输入
        bucket_name_ptr = ctypes.c_char_p(bucket_name.encode('utf-8'))

        # 通过调用导出的golang函数打开存储桶(如果不存在)
        bucket_result = self.uplink.m_libuplink.uplink_ensure_bucket(self.project, bucket_name_ptr)
        #
        # 如果发生错误
        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.."这一行

补充
使用Web界面创建新的存储桶时没有错误

参考
https://storj-thirdparty.github.io/uplink-python/#/library?id=ensure_bucketbucket_name

https://github.com/storj/uplink/blob/8da069b86063ee9671cc85cc44eaa6b8baf84b58/bucket.go#L97
英文:

I'm trying to create a new storj bucket with uplink-python
Does anyone know this error ?

Thank you

class Storage:
def __init__(self, api_key: str, satellite: str, passphrase: str, email: str):
&quot;&quot;&quot;
account Storj
&quot;&quot;&quot;
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() &lt;-- open the project
def create_bucket(self, mybucket: str):
&quot;&quot;&quot;
Create un bucket and ingnores the error if it already exist
&quot;&quot;&quot;
print(mybucket)
self.project.ensure_bucket(mybucket)
def get_bucket(self, mybucket: str):
&quot;&quot;&quot;
verify bucket
&quot;&quot;&quot;
print(mybucket)
return self.project.stat_bucket(mybucket)
def close(self):
self.project.close()
storage = Storage(api_key=&quot;zzz&quot;, satellite=&quot;.storj.io:7777&quot;, passphrase=&quot;passtest&quot;, mail=&quot;bucket@bucket.com&quot;)

Verify the old bucket

storage.get_bucket(&quot;demo01&quot;) # it&#39;s works

Create a new bucket

storage.create_bucket(&quot;Hello&quot;) # internal error

output:

> File "../test/uplink/lib/python3.9/site-packages/uplink_python/project.py", line 121, in ensure_bucket
raise _storj_exception(bucket_result.error.contents.code,
uplink_python.errors.InternalError: 'internal error'

line 121

    def ensure_bucket(self, bucket_name: str):
&quot;&quot;&quot;
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
&quot;&quot;&quot;
#
# 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(&#39;utf-8&#39;))
# open bucket if doesn&#39;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(&quot;utf-8&quot;))
return self.uplink.bucket_from_result(bucket_result.bucket)

The "internal error" message comes from that "raise _storj_exception.."

add:
There are no error creating a new bucket with web interface

ref :
https://storj-thirdparty.github.io/uplink-python/#/library?id=ensure_bucketbucket_name

https://github.com/storj/uplink/blob/8da069b86063ee9671cc85cc44eaa6b8baf84b58/bucket.go#L97

答案1

得分: 0

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

storage.create_bucket("Hello")

替换为

storage.create_bucket("hello")

使用uplink-Python创建一个新的storj存储桶。

编辑:
这就是原因:
https://forum.storj.io/t/bucket-name-uppercase/20554/2?u=mike1

英文:

Solved:
an upper case letter in the bucket name causes the internal error...

replace

storage.create_bucket(&quot;Hello&quot;)

with

storage.create_bucket(&quot;hello&quot;)

使用uplink-Python创建一个新的storj存储桶。

EDIT:
that's why:
https://forum.storj.io/t/bucket-name-uppercase/20554/2?u=mike1

huangapple
  • 本文由 发表于 2022年12月2日 07:37:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/74649328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定