<bdo id='4VJLz'></bdo><ul id='4VJLz'></ul>

<legend id='4VJLz'><style id='4VJLz'><dir id='4VJLz'><q id='4VJLz'></q></dir></style></legend>

      <tfoot id='4VJLz'></tfoot>

      <small id='4VJLz'></small><noframes id='4VJLz'>

      <i id='4VJLz'><tr id='4VJLz'><dt id='4VJLz'><q id='4VJLz'><span id='4VJLz'><b id='4VJLz'><form id='4VJLz'><ins id='4VJLz'></ins><ul id='4VJLz'></ul><sub id='4VJLz'></sub></form><legend id='4VJLz'></legend><bdo id='4VJLz'><pre id='4VJLz'><center id='4VJLz'></center></pre></bdo></b><th id='4VJLz'></th></span></q></dt></tr></i><div id='4VJLz'><tfoot id='4VJLz'></tfoot><dl id='4VJLz'><fieldset id='4VJLz'></fieldset></dl></div>

        如何使用 GAE 的 Python API 将原始字节写入 Google 云存储

        How to write raw bytes to Google cloud storage with GAE#39;s Python API(如何使用 GAE 的 Python API 将原始字节写入 Google 云存储)

            <tbody id='gRGfv'></tbody>

        1. <tfoot id='gRGfv'></tfoot>

              • <small id='gRGfv'></small><noframes id='gRGfv'>

                <i id='gRGfv'><tr id='gRGfv'><dt id='gRGfv'><q id='gRGfv'><span id='gRGfv'><b id='gRGfv'><form id='gRGfv'><ins id='gRGfv'></ins><ul id='gRGfv'></ul><sub id='gRGfv'></sub></form><legend id='gRGfv'></legend><bdo id='gRGfv'><pre id='gRGfv'><center id='gRGfv'></center></pre></bdo></b><th id='gRGfv'></th></span></q></dt></tr></i><div id='gRGfv'><tfoot id='gRGfv'></tfoot><dl id='gRGfv'><fieldset id='gRGfv'></fieldset></dl></div>
                <legend id='gRGfv'><style id='gRGfv'><dir id='gRGfv'><q id='gRGfv'></q></dir></style></legend>
                  <bdo id='gRGfv'></bdo><ul id='gRGfv'></ul>

                • 本文介绍了如何使用 GAE 的 Python API 将原始字节写入 Google 云存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试修改用户表单提交的一些二进制数据,并将其写入谷歌云存储.我尝试遵循 Google 文档的示例,但在编写时出现了诸如如:

                  I am trying to modify some binary data submitted by user form, and write it to Google Cloud Storage. I tried to follow Google document's example, but upon writing I got errors such as:

                  UnicodeDecodeError:ascii"编解码器无法解码位置 34 中的字节 0xe5:序数不在范围内.

                  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 34: ordinal not in range.

                  我的代码如下

                  gcs_file = gcs.open(filename,'w',content_type='audio/mp3')
                  gcs_file.write(buf)
                  gcs_file.close()
                  

                  我尝试使用wb"模式打开文件,但得到无效模式 wb".错误.

                  I tried to open file with 'wb' mode but got a "Invalid mode wb." error.

                  我在 GCS 的邮件列表 发现了一个类似的问题在 Java 上.GCS 开发团队的建议是使用 writeChannel.write() 而不是 PrintWriter.有人可以建议如何让它在 Python 中工作吗?

                  I found a similar question at GCS's maillist which was on Java. There the GCS develop team's suggest was to use writeChannel.write() instead of PrintWriter. Could anybody suggest how to make it work in Python?

                  推荐答案

                  我想问题是 gcs_file.write() 方法需要str"类型的数据.由于您的 buf 类型是unicode"并且显然包含一些 Unicode 字符(可能在 ID3 标签中),因此您会得到 UnicodeDecodeError.所以你只需要将 buf 编码为 UTF-8:

                  I suppose the problem is that gcs_file.write() method expects data of type "str". Since type of your buf is "unicode" and apparently contains some Unicode chars (maybe in ID3 tags), you get UnicodeDecodeError. So you just need to encode buf to UTF-8:

                  gcs_file = gcs.open(filename,'w',content_type='audio/mp3')
                  gcs_file.write(buf.encode('utf-8'))
                  gcs_file.close()
                  

                  这篇关于如何使用 GAE 的 Python API 将原始字节写入 Google 云存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                  <i id='JnJeD'><tr id='JnJeD'><dt id='JnJeD'><q id='JnJeD'><span id='JnJeD'><b id='JnJeD'><form id='JnJeD'><ins id='JnJeD'></ins><ul id='JnJeD'></ul><sub id='JnJeD'></sub></form><legend id='JnJeD'></legend><bdo id='JnJeD'><pre id='JnJeD'><center id='JnJeD'></center></pre></bdo></b><th id='JnJeD'></th></span></q></dt></tr></i><div id='JnJeD'><tfoot id='JnJeD'></tfoot><dl id='JnJeD'><fieldset id='JnJeD'></fieldset></dl></div>
                    <tbody id='JnJeD'></tbody>
                  <legend id='JnJeD'><style id='JnJeD'><dir id='JnJeD'><q id='JnJeD'></q></dir></style></legend>

                  1. <small id='JnJeD'></small><noframes id='JnJeD'>

                    <tfoot id='JnJeD'></tfoot>

                        <bdo id='JnJeD'></bdo><ul id='JnJeD'></ul>