英文:
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):
"""
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")
Verify the old bucket
storage.get_bucket("demo01") # it's works
Create a new bucket
storage.create_bucket("Hello") # 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):
"""
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)
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")
编辑:
这就是原因:
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("Hello")
with
storage.create_bucket("hello")
EDIT:
that's why:
https://forum.storj.io/t/bucket-name-uppercase/20554/2?u=mike1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论