关于python:Duplicity与Google Cloud抛出TypeError

关于python:Duplicity与Google Cloud抛出TypeError

一段时间以来,我一直成功地使用 duplicity 备份到 GCS,但几个月前它停止工作了。我认为迁移到 Python 3 存在编码问题。我看到过一些类似的问题(例如,https://bugs.launchpad.net/duplicity/+bug/1843995) 声称类似的错误已得到解决,但我仍然收到以下信息:

Traceback (innermost last):
  File "/usr/bin/duplicity", line 106, in <module>
    with_tempdir(main)
  File "/usr/bin/duplicity", line 92, in with_tempdir
    fn()
  File "/usr/lib/python3/dist-packages/duplicity/dup_main.py", line 1525, in main
    action = commandline.ProcessCommandLine(sys.argv[1:])
  File "/usr/lib/python3/dist-packages/duplicity/commandline.py", line 1175, in ProcessCommandLine
    globals.backend = backend.get_backend(args[0])
  File "/usr/lib/python3/dist-packages/duplicity/backend.py", line 225, in get_backend
    obj = get_backend_object(url_string)
  File "/usr/lib/python3/dist-packages/duplicity/backend.py", line 211, in get_backend_object
    return factory(pu)
  File "/usr/lib/python3/dist-packages/duplicity/backends/_boto_single.py", line 173, in __init__
    self.resetConnection()
  File "/usr/lib/python3/dist-packages/duplicity/backends/_boto_single.py", line 198, in resetConnection
    self.bucket = self.conn.create_bucket(self.bucket_name,
  File "/usr/lib/python3/dist-packages/boto/gs/connection.py", line 93, in create_bucket
    response = self.make_request(
  File "/usr/lib/python3/dist-packages/boto/s3/connection.py", line 659, in make_request
    auth_path = self.calling_format.build_auth_path(bucket, key)
  File "/usr/lib/python3/dist-packages/boto/s3/connection.py", line 94, in build_auth_path
    path = '/' + bucket
 TypeError: can only concatenate str (not "bytes") to str

答案1

你可能没有使用最新的https://launchpad.net/duplicity/+milestone/0.8.14

自移植到 python3 以来,许多编码错误已被修复。

如果您要备份到 S3,还有基于维护的 boto3 模块的新 boto3+s3://。

这是发布公告中的安装说明(请先按照底部的建议删除发行版的重复性)

有多种稳定和日常选择:

注意:如果 duplicity 是通过发行版存储库安装的,请先卸载它。对于 Ubuntu,卸载方法是“sudo apt-get purge duplicity”。

..ede/duply.net

答案2

我的方式:

  1. virtualenv --python=/usr/bin/python3 venv/
  2. source venv/bin/activate
  3. git clone [email protected]:boto/boto.git -b develop
  4. 在 boto/utils.py:871 中将以下行修补为value = str(value.encode('utf-8'))
  5. 来自 boto/python setup.py install
  6. git clone https://github.com/henrysher/duplicity
  7. cd duplicity&&python setup.py install

相关内容