How to set the properties of an Azure Table through python sdk

旧时模样 提交于 2019-12-24 15:27:37

问题


I am trying to enable CORS for a specific azure account/table from the python sdk.

Unfortunately the docs do not cover that topic. From looking here I know that I must use the set_table_service_properties() and pass the storage_service_properties argument. But I don't know how is this argument supposed to be formatted.

Should I create a dictionary that when passed to the xml converted will produce something like that?

<?xml version="1.0" encoding="utf-8"?>
<StorageServiceProperties>
    <Logging>
        <Version>1.0</Version>
        <Delete>true</Delete>
        <Read>false</Read>
        <Write>true</Write>
        <RetentionPolicy>
            <Enabled>true</Enabled>
            <Days>7</Days>
        </RetentionPolicy>
    </Logging>
    <HourMetrics>
        <Version>1.0</Version>
        <Enabled>true</Enabled>
        <IncludeAPIs>false</IncludeAPIs>
        <RetentionPolicy>
            <Enabled>true</Enabled>
            <Days>7</Days>
        </RetentionPolicy>
    </HourMetrics>
    <MinuteMetrics>
        <Version>1.0</Version>
        <Enabled>true</Enabled>
        <IncludeAPIs>true</IncludeAPIs>
        <RetentionPolicy>
            <Enabled>true</Enabled>
            <Days>7</Days>
        </RetentionPolicy>
    </MinuteMetrics>
    <Cors>
        <CorsRule>
            <AllowedOrigins> http://www.fabrikam.com,http://www.contoso.com</AllowedOrigins>
            <AllowedMethods>GET,PUT</AllowedMethods>
            <MaxAgeInSeconds>500</MaxAgeInSeconds>
            <ExposedHeaders>x-ms-meta-data*,x-ms-meta-customheader</ExposedHeaders>
            <AllowedHeaders>x-ms-meta-target*,x-ms-meta-customheader</AllowedHeaders>
        </CorsRule>
    </Cors>
</StorageServiceProperties>

回答1:


This is shortly going to be fixed in the next version of the Python library (to be released very soon, see the dev branch), but at the moment the library doesn't support setting CORS.

In the new version, it will be settable something like this sample shows.



来源:https://stackoverflow.com/questions/35342136/how-to-set-the-properties-of-an-azure-table-through-python-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!