Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B2 backend import error message could reveal the missing module #14

Open
jshprentz opened this issue Dec 20, 2017 · 7 comments
Open

B2 backend import error message could reveal the missing module #14

jshprentz opened this issue Dec 20, 2017 · 7 comments

Comments

@jshprentz
Copy link

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.

@NZJourneyMan
Copy link

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.

@tobypeschel
Copy link

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.

@mauricev
Copy link

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?

@mauricev
Copy link

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.

@cosimo
Copy link

cosimo commented Nov 4, 2020

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).

@Rufflewind
Copy link

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

@asgh
Copy link

asgh commented Dec 11, 2020

b2 version 1.4.2 and b2sdk version 1.1.4 work.

mrrobot47 pushed a commit to mrrobot47/duplicity that referenced this issue Dec 17, 2020
Sometimes import can fail because one of B2's dependencies is broken.

The trick here is to query the "name" attribute of ModuleNotFoundError
to see if B2 is the module that failed. Unfortunately this only works on
Python 3.6+. In older versions, the original behavior is retained.

This partially mitigates the issue described in
henrysher/duplicity#14.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants