diff --git a/libcloud/__init__.py b/libcloud/__init__.py index 725c3dee8b..9ebb78f103 100644 --- a/libcloud/__init__.py +++ b/libcloud/__init__.py @@ -55,12 +55,22 @@ def _init_once(): This checks for the LIBCLOUD_DEBUG environment variable, which if it exists is where we will log debug information about the provider transports. """ + from libcloud.utils.py3 import PY3 + path = os.getenv('LIBCLOUD_DEBUG') if path: - fo = codecs.open(path, 'a', encoding='utf8') + mode = 'a' + + # Special case for /dev/stderr and /dev/stdout on Python 3. + # Opening those files in append mode will throw "illegal seek" + # exception there. + if path in ['/dev/stderr', '/dev/stdout'] and PY3: + mode = 'w' + + fo = codecs.open(path, mode, encoding='utf8') enable_debug(fo) - if have_paramiko: - paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) + if have_paramiko: + paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) _init_once() diff --git a/libcloud/common/base.py b/libcloud/common/base.py index ac0fdd7d47..d4cbbae19f 100644 --- a/libcloud/common/base.py +++ b/libcloud/common/base.py @@ -313,7 +313,7 @@ def _log_response(self, r): ht += "\r\n" # this is evil. laugh with me. ha arharhrhahahaha - class fakesock: + class fakesock(object): def __init__(self, s): self.s = s @@ -324,7 +324,7 @@ def makefile(self, *args, **kwargs): else: cls = StringIO - return cls(self.s) + return cls(b(self.s)) rr = r headers = lowercase_keys(dict(r.getheaders()))