【问题标题】:Using boto in python 3在 python 3 中使用 boto
【发布时间】:2016-09-02 00:39:05
【问题描述】:

我有 boto 2.3.0 neo 分支和 python 3.3。 我用 boto 从 simpledb 收集数据,效果很好。 但是现在当我尝试 boto 连接到 s3 时出现错误。谁能指导我正确的方向。我真的不想降级我的 python,因为我的整个项目都在 python 3.3 中。

这是我写的命令列表:

       >>> from boto.s3.key import Key
       >>> k = Key(bucket)
       >>> k.key='testfile'
       >>> k.set_contents_from_string('Hello this is my Boto S3 Test')

这是我在执行最后一个命令时遇到的错误列表:

       Traceback (most recent call last):
       File "<pyshell#8>", line 1, in <module>
       k.set_contents_from_string('Hello this is my Boto S3 Test')
       File "C:\Python33\lib\site-packages\boto\s3\key.py", line 1060, in              
       set_contents_from_string
       fp = compat.StringIO(s)
       TypeError: initial_value must be str or None, not bytes

我一直遇到的其他问题(我猜root是一样的)在这个链接中给出:

iter() returned non-iterator of type 'Key' : boto amazon s3

【问题讨论】:

  • 有一个py3kport 分支,也许你应该试试。正式发布的版本只有supports python2.5 - 2.7
  • 是的,我猜。现在 Iv 意识到除了一些列表功能之外,python 3.3 并没有真正使用太多 Iv。猜猜我必须回到 2.7 :( 希望在 python 3.x 中 boto 有一些稳定的东西。

标签: python python-3.x boto


【解决方案1】:

实际上 boto 可以在 Python 3 中运行。

设置:

【讨论】:

    【解决方案2】:

    是的,简短的回答...您必须重构,这不一定是一件坏事,因为这应该被移植到 3。尝试在源代码上运行 2to3 并使用 Python3 构建...解决任何问题在构建过程中出现...如果您在项目中使用大量 boto 功能,那么需要处理的问题将比上面的答案少。

    【讨论】:

    • 谢谢,但我回到使用 2.X 并且该项目现在已经成功结束,所以我想下次:)
    【解决方案3】:

    这个问题看起来像是 StringIO 与 BytesIO 的问题。在这里查看线索:

    https://docs.python.org/2/library/io.html

    【讨论】:

      【解决方案4】:

      我遇到了完全相同的问题,并写了small python package 来解决它。这将让你创建一个 python2 virtualenv,并将 boto 包无缝导入你的 python3 包中。

      或者,您可以执行awscli 的系统安装(它使用python2,因为它基于boto),然后通过subprocess.check_call() 调用它。

      【讨论】:

        猜你喜欢
        • 2014-02-10
        • 2018-07-14
        • 2016-06-17
        • 2017-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-17
        • 1970-01-01
        相关资源
        最近更新 更多