简体   繁体   中英

azure blob storage classes to python dictionaries?

this sounds like it should be simple but im having a terrible time here.

Im using the azure python sdk, latest version. I'm able to reach the endpoint, get data etc.... but things come down in azure custom classes. In the end they are mostly just dictionaries but some formatting is messed up. Like an entry in the dict, rather than an actual date, it comes back as a "datetime.datetime(2021, 05....etc.

I've been trying to parse and fix these things but I feel like there should be a better way. Now im onto a blob storage class that contains multiple sub dicts. I'm trying to detect if the value in the kv pair is a dict, but instead the type is " <class 'azure.storage.blob._models.ContentSettings'> ". I'm not that familiar with Azure, is there a way to return the data in these classes as actual python dicts?

If not, is there a way for me to use isinstance on something like <class 'azure.storage.blob._models.ContentSettings'>?

thx.

best method i could work up for now as to create a function to pass all received kv pairs to and format them, if need be, then returned the formatted version and add it to the new dict.

i do a check on each pair to see if the value in the pair has a.items() possibility, if so it runs that set through the formatting function.

I feel like theres a better way but for now it seems this gets me an output that is readable and json friendly.

The formatter function looks like this.

def formatAzureSpecialChars(self, k, v) -> list:
    if k == 'encryption_scope' or k == 'blob_type':
        v = str(v)
        v.replace("'", "")
        v = str(v)
        return(True, v)
    elif isinstance(v, datetime.datetime):
        v = v.strftime("%Y-%m-%d_T%H-%M-%S")
        return(True, v)
    elif k == 'content_md5':
        v = v.hex()
        return(True, v)
    else:
        return(False, v)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM