certbot/certbot

ImportError: cannot import name UnrewindableBodyError

ITTWTTI opened this issue ยท 9 comments

Traceback (most recent call last):
File "/usr/bin/certbot", line 9, in
load_entry_point('certbot==0.39.0', 'console_scripts', 'certbot')()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2852, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2443, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2449, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python2.7/site-packages/certbot/main.py", line 17, in
from certbot import account
File "/usr/lib/python2.7/site-packages/certbot/account.py", line 17, in
from acme import messages
File "/usr/lib/python2.7/site-packages/acme/messages.py", line 11, in
from acme import challenges
File "/usr/lib/python2.7/site-packages/acme/challenges.py", line 12, in
import requests
File "/usr/lib/python2.7/site-packages/requests/init.py", line 58, in
from . import utils
File "/usr/lib/python2.7/site-packages/requests/utils.py", line 32, in
from .exceptions import InvalidURL
File "/usr/lib/python2.7/site-packages/requests/exceptions.py", line 10, in
from urllib3.exceptions import HTTPError as BaseHTTPError
File "/usr/lib/python2.7/site-packages/urllib3/init.py", line 10, in
from .connectionpool import (
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 31, in
from .connection import (
File "/usr/lib/python2.7/site-packages/urllib3/connection.py", line 45, in
from .util.ssl_ import (
File "/usr/lib/python2.7/site-packages/urllib3/util/init.py", line 5, in
from .request import make_headers
File "/usr/lib/python2.7/site-packages/urllib3/util/request.py", line 5, in
from ..exceptions import UnrewindableBodyError
ImportError: cannot import name UnrewindableBodyError

bmw commented

Your requests or urllib3 installation is broken, probably from having a mix of Python packages installed from both yum and pip. I highly recommend never using pip outside of a virtual environment to avoid problems like this.

Unfortunately, helping you fix the Python installation on your system is not something we're able to do, but there is a large community of people at https://community.letsencrypt.org that should be able to help you if you create a post there.

It is ridiculous that almost every time I run any software written with python, some bizarre error pops up, and people still choose to write software in python.

I am running Centos 7 and I just ran into the exact same issue. Anyways, for future reference, here is what worked for me:

sudo pip uninstall requests
sudo pip uninstall urllib3
sudo yum remove python-urllib3
sudo yum remove python-requests
sudo yum install python-urllib3
sudo yum install python-requests

From ansible/tower-cli#603

bmw commented

Issues like this are really common unfortunately and are caused by installing Python packages globally on your system through both your OS package manager (e.g. yum) and pip. The two different package managers do not work well together and can result in packages installed with conflicting dependencies or broken package installations because the two package managers improperly modify packages installed by the other.

The general solution for this I recommend is to never use pip outside of a virtual environment and only install Python packages globally through your package manager.

We're currently reworking how we distribute Certbot outside of distros and we will have our Python packages separate from those provided by your OS which should avoid these problems entirely.

for those that have stuff that depend on python-requests and python-urllib3 that they rather wouldn't remove:

sudo pip uninstall requests
sudo pip uninstall urllib3
sudo yum reinstall python-urllib3
sudo yum reinstall python-requests

Worked for me.

@bmw The thing is, at least for my case, it is an almost clean installation of CentOS 7 - Literally, the only thing I installed before certbot is Nginx. I do not use Python myself at all and I certainly have not installed either requests or urllib3 myself. The instructions provided on the Certbot website just doesn't work.

bmw commented

@SCLeoX, if you're able to provide instructions on how to reproduce the problem from a common base image such as the CentOS 7 Docker image (without using pip), please open a new issue and we'll happily take a look.

I highly recommend never using pip outside of a virtual environment to avoid problems like this.

You forgot to mention that in a multitenant (by user, purpose, etc) environment, you should only be using docker, virtualenv or other means to isolate a process and its deps, which means, um, use pip; otherwise, you should use the defacto python package manager, again pip, because it's a constant across multiple environments, distros, etc.

So, pip.

I found that yum was failing to install python-urllib3 with this error:

error: unpacking of archive failed on file /usr/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname: cpio: rename

I had tried uninstalling urllib3 via yum and pip and still got that error. Prompted by this answer, I removed the /usr/lib/python2.7/site-packages/urllib3 directory. After that I was able to install everything successfully.

bw2k commented

I found that yum was failing to install python-urllib3 with this error:

error: unpacking of archive failed on file /usr/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname: cpio: rename

I had tried uninstalling urllib3 via yum and pip and still got that error. Prompted by this answer, I removed the /usr/lib/python2.7/site-packages/urllib3 directory. After that I was able to install everything successfully.

Thanks to you, i was able to fix this weird error.