diff --git a/wakatime/compat.py b/wakatime/compat.py index 3abbfa5..ba8f107 100644 --- a/wakatime/compat.py +++ b/wakatime/compat.py @@ -40,6 +40,7 @@ elif is_py3: # pragma: nocover open = open basestring = (str, bytes) + try: from importlib import import_module except ImportError: # pragma: nocover diff --git a/wakatime/packages/requests/certs.py b/wakatime/packages/requests/certs.py index 07e6475..47cc228 100644 --- a/wakatime/packages/requests/certs.py +++ b/wakatime/packages/requests/certs.py @@ -11,6 +11,7 @@ If you are packaging Requests, e.g., for a Linux distribution or a managed environment, you can change the definition of where() to return a separately packaged CA bundle. """ +import sys import os.path try: @@ -19,7 +20,13 @@ except ImportError: def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests - return os.path.join(os.path.dirname(__file__), 'cacert.pem') + is_py3 = (sys.version_info[0] == 3) + certdir = os.path.dirname( + __file__ + if is_py3 else + __file__.decode(sys.getfilesystemencoding()) + ) + return os.path.join(certdir, 'cacert.pem') if __name__ == '__main__': print(where())