Home  >  Q&A  >  body text

七牛python sdk保存文件到七牛云存储,无法处理数据中尖括号

比如下面这样的数据

    <!doctype html>
    <html xmlns:ng="http://angularjs.org">
        <body>
            Hello {{'World'}}!
            <script src="http://code.angularjs.org/angular.js"></script>
            <script>
                angular.element(document).ready(function() {
                angular.bootstrap(document);
                });
            </script>
        </body>
    </html>

我想通过StringIO的方式保存到七牛云存储,得到不同的结果

实现的代码参考了七牛python sdk的文档

policy = qiniu.rs.PutPolicy(bucket_name)
uptoken = policy.token()

extra = qiniu.io.PutExtra()
extra.mime_type = "text/plain"
extra.params = {'x:a': 'a'}

data = u"""
## 概览
    <!doctype html>
    <html xmlns:ng="http://angularjs.org">
        <body>
            Hello {{'World'}}!
            <script src="http://code.angularjs.org/angular.js"></script>
            <script>
                angular.element(document).ready(function() {
                angular.bootstrap(document);
                });
            </script>
        </body>
    </html>

下面是一些你的代码必须遵守的顺序:

1. 等页面和所有的脚本加载完之后,找到HTML模板的根节点——通常就是文档的根节点。
2. 调用 api/angular.bootstrap将模板编译成可执行的、数据双向绑定的应用程序。

<span class="doc-copyright">**版权声明:** **中文文档[AngularJS中文社区][]** && **英文文档[AngularJS官网][]** && **代码许可[The MIT License][]** && **文档许可[CC BY 3.0][]**</span>"
"""

data = data.strip().encode('utf-8')
data = str(data)

strio = StringIO.StringIO()
strio.write(data)


result, error = qiniu.io.put(uptoken, 'xxx', strio, extra)
print error

不知道怎么解决...请教

高洛峰高洛峰2765 days ago515

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 13:28:01

    Reporting this errorlimited mimeType: ExpUser can only upload image/audio/video/plaintext means that you are an experience user. Qiniu Service has more content and determines that the field you uploaded is not plaintext, but an html file (experience users cannot upload html files), causing the upload to fail. , so it is recommended that you become a standard user through the following identity authentication, so that you can avoid masking.

    reply
    0
  • Cancelreply