henrysher / duplicity

mirror of duplicity: https://code.launchpad.net/duplicity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

B2 backend import error message could reveal the missing module

jshprentz opened this issue · comments

While trying to backup to Backblaze, Duplicity raised a BackendException reporting, "B2 backend requires B2 Python APIs (pip install b2)". The b2 module already was installed, but supporting SQLite development files were not, so the actual import failure was for the _sqlite3 module. An improved BackendException message could reveal the actual problem and reduce debugging time.

Environment

  • Ubuntu 14.04
  • Locally compiled Python 2.7.14 in a virtual environment
  • Duplicity 0.7.15

The Long Story

A check in my Python virtual environment confirmed that b2 was already installed.

(venv)joel@krakatoa:/opt/duplicity$ python
Python 2.7.14 (default, Dec 17 2017, 21:42:27)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import b2
>>>

To better understand the cause of the exception, I modified b2backend.py to include ImportError details in the raised BackendException.

(venv)joel@krakatoa:/opt/duplicity$ diff duplicity-0.7.15/duplicity/backends/b2backend.py venv/lib/python2.7/site-packages/duplicity/backends/b2backend.py
64,65c64,65
<         except ImportError:
<             raise BackendException('B2 backend requires B2 Python APIs (pip install b2)')
---
>         except ImportError as err:
>             raise BackendException('B2 backend requires B2 Python APIs (pip install b2): {}'.format(err))

Rerunning Duplicity gave this more informative message: "BackendException: B2 backend requires B2 Python APIs (pip install b2): No module named _sqlite3".

My server runs Ubuntu 14.04, which froze Python at version 2.7.6. To satisfy Duplicity's need for version 2.7.9 or later, I downloaded and compiled the latest Python 2.7, which is version 2.7.14. My Ubuntu server lacked the SQLite 3 development files, so my Python build omitted SQLite support.

I corrected the problem by installing the Ubuntu libsqlite3-dev package, rebuilding Python, and rebuilding Duplicity. With SQLite support in Python, Duplicity successfully backs up to Backblaze.

I also had similar issues with the BackendException not reporting the underlying issue. In my case I guessed what the issue was and ran the b2 executable directly which gave me a stacktrace telling me what module was missing and how to fix it. The underlying issue is the b2 pip package is missing one or more dependencies.

I've run into this issue multiple times, and each time it's urllib3 with b2.api. A quick pip install urllib3 --upgrade fixes it, in my case from version urllib3-1.22 to urllib3-1.25.6. I agree BackendException could be more detailed.

This bug has still not been fixed. I am getting "b2" not being installed. But what I installed is b2sdk, so is it looking for the wrong thing?

When I manually loaded each module, for the first one, from b2sdk.api import B2Api, I got
ModuleNotFoundError: No module named 'sqlite3'

Not sure why the error code suggested above reported "b2" and not sqlite3, but the cause in my case is the same as the original poster's.

When I manually loaded each module, for the first one, from b2sdk.api import B2Api, I got
ModuleNotFoundError: No module named 'sqlite3'

Not sure why the error code suggested above reported "b2" and not sqlite3, but the cause in my case is the same as the original poster's.

@mauricev, I think that on python 2.7 you need to downgrade the b2 module. I did and that worked for me.

 pip install b2==1.0.0

(or try different values for the version number).

Merge request to partially mitigate this issue on Python 3.6+: https://gitlab.com/duplicity/duplicity/-/merge_requests/33

commented

b2 version 1.4.2 and b2sdk version 1.1.4 work.