wakatime / sublime-wakatime

Sublime Text 2 & 3 plugin for automatic time tracking and metrics generated from your programming activity.
https://wakatime.com/sublime-text
BSD 3-Clause "New" or "Revised" License
525 stars 47 forks source link

Encoding Error (Response 102) #33

Closed sisou closed 9 years ago

sisou commented 9 years ago

On every action in Sublime Plugin:

Traceback (most recent call last):
  File ".\logging\__init__.py", line 768, in emit
  File ".\logging\__init__.py", line 648, in format
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\log.py", line 62, in format
    return CustomEncoder().encode(data)
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 264, in encode
    chunks = list(chunks)
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 612, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 535, in _iterencode_dict
    yield _encoder(value)
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 65, in py_encode_basestring_ascii
    s = s.decode('utf-8')
  File ".\encodings\utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 29-31: invalid data
[WakaTime] Error: Response code 102 from wakatime package.

I use utf8, Sublime 2, Windows is in German, Window 7 x64

Also, nothing is being written in the wakatime.log file in my Home Folder.

alanhamlett commented 9 years ago

Latest version released today(v3.0.11) of the plugin might fix this, since simplejson was updated to it's latest version. Can you try it out?

sisou commented 9 years ago

It's not yet updated in Package Control (I saw you released it just 15 min ago). Can I just copy the new release over the 3.0.10 in Sublime's Packages folder?

alanhamlett commented 9 years ago

It's updated now. I think you can force an update by re-launching ST.

sisou commented 9 years ago

I waited until Package Control said 3.0.11 and installed it again, but sadly, the error remains:

Traceback (most recent call last):
  File ".\logging\__init__.py", line 768, in emit
  File ".\logging\__init__.py", line 648, in format
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\log.py", line 62, in format
    return CustomEncoder().encode(data)
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 271, in encode
    chunks = list(chunks)
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 632, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 561, in _iterencode_dict
    yield _encoder(value)
  File "C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\WakaTime\packages\wakatime\packages\simplejson\encoder.py", line 65, in py_encode_basestring_ascii
    s = s.decode('utf-8')
  File ".\encodings\utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 29-31: invalid data
[WakaTime] Error: Response code 102 from wakatime package.

I installed Python 3, should I use 2.* instead?

How can I give you any more info about what could be the issue?

alanhamlett commented 9 years ago

I think I've fixed the problem with 1a6f588d94cdefeb0c87e4094c4bd6b00f577f91, you can use v3.0.12 or uninstall WakaTime with Package Control then copy the sublime-wakatime repo folder into C:\Users\Soeren\AppData\Roaming\Sublime Text 2\Packages\.

sisou commented 9 years ago

After a bit of wrangling (I don't know python) I managed to get this as the data:

OrderedDict([('now', '2015/03/23 22:08:53 Westeurop\xe4ische Zeit'), ('version', '4.0.4'), ('plugin', 'sublime/2221 sublime-wakatime/3.0.11'), ('time', 1427148533.3469999), ('file', u'C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\log.py'), ('level', 'WARNING'), ('message', {'SSLError': u'[Errno 1] _ssl.c:480: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm', 'traceback': 'Traceback (most recent call last):\n  File "C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\base.py", line 351, in send_heartbeat\n    proxies=proxies)\n  File "C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\packages\\requests\\api.py", line 99, in post\n    return request(\'post\', url, data=data, json=json, **kwargs)\n  File "C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\packages\\requests\\api.py", line 49, in request\n    response = session.request(method=method, url=url, **kwargs)\n  File "C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\packages\\requests\\sessions.py", line 461, in request\n    resp = self.send(prep, **send_kwargs)\n  File "C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\packages\\requests\\sessions.py", line 573, in send\n    r = adapter.send(request, **kwargs)\n  File "C:\\Users\\Soeren\\AppData\\Roaming\\Sublime Text 2\\Packages\\WakaTime\\packages\\wakatime\\packages\\requests\\adapters.py", line 431, in send\n    raise SSLError(e, request=request)\nSSLError: [Errno 1] _ssl.c:480: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm\n'})])

The characters in position 29-31 are apparently invalid.

Will try to overwrite with the new version now.

sisou commented 9 years ago

Seems like it's the German umlaut ä that is causing the issue (Westeuropäische Zeit)

sisou commented 9 years ago

The issue persists... :(

alanhamlett commented 9 years ago

Thanks! I'll get a fix out soon.

alanhamlett commented 9 years ago

So I'll fix the encoding issue, but the original problem is:

SSLError: [Errno 1] _ssl.c:480: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm

This looks like an old version of ssl, maybe from using an old version of Python?

sisou commented 9 years ago
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.1l 15 Jan 2015

Seems like it's fresh enough. I just downloaded and installed Python yesterday.

sisou commented 9 years ago

After a bit of experimenting with a custom plugin, I found that Sublime Text 2 on Windows ships with it's own Python interpreter for plugins: v2.6. That version doesn't support the newer SSL cyphers, that's why it's failing.

I am now in the process of finding out how to get Sublime to use a newer Python, if that is possible at all. According to http://stackoverflow.com/a/28591892/4204380, only Sublime on OSX uses the system's python version for plugins.

Edit 1: It seems like the only way to get the new SSL cyphers is to switch to ST3, which ships with Python v3.

Edit 2: According to http://stackoverflow.com/a/15276533/4204380, it is not possible to upgrade the bundled Python without breaking ST2. That's it then. Let's try ST3.

Edit 3: Sadly, this SSL incompatibility means that WakaTime does not support ST2 anymore (only on Windows?)

sisou commented 9 years ago

Found the issue:

Sublime Text 2's Python ships with an SSL module. A very old one, but it's still there. But it's so minimal, it doesn't even include the ssl.OPENSSL_VERSION attribute.

This means, that when WakaTime.py is checking for SSL support, it does find it and thus doesn't run its python_binary() search function. Thus the system's Python SSL version is not used and API requests fail with the wakatime.com's newer SSL cypher.

The trick is to try to call ssl.OPENSSL_VERSION in the try...except structure (https://github.com/wakatime/sublime-wakatime/blob/master/WakaTime.py#L43), like this (before the HAS_SSL variable is set to true):

try:
    import ssl
    import socket
    assert ssl
    assert socket.ssl
    ssl.OPENSSL_VERSION
    HAS_SSL = True
except (ImportError, AttributeError):
    from subprocess import Popen

Now, WakaTime correctly checks the system for a Python interpreter and uses that together with its SSL module, instead of the bundled version.

alanhamlett commented 9 years ago

Oh great work debugging this! v3.0.13 includes the extra SSL check.