Home > Blockchain >  Create a new storj bucket with uplink-Python
Create a new storj bucket with uplink-Python

Time:12-08

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="[email protected]")

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

CodePudding user response:

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

  • Related