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

Encoding Error (Response 102) #33

Closed
sisou opened this issue Mar 23, 2015 · 14 comments
Closed

Encoding Error (Response 102) #33

sisou opened this issue Mar 23, 2015 · 14 comments

Comments

@sisou
Copy link

sisou commented Mar 23, 2015

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
Copy link
Member

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
Copy link
Author

sisou commented Mar 23, 2015

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
Copy link
Member

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

@sisou
Copy link
Author

sisou commented Mar 23, 2015

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
Copy link
Member

I think I've fixed the problem with 1a6f588, 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
Copy link
Author

sisou commented Mar 23, 2015

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
Copy link
Author

sisou commented Mar 23, 2015

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

@sisou
Copy link
Author

sisou commented Mar 23, 2015

The issue persists... :(

@alanhamlett
Copy link
Member

Thanks! I'll get a fix out soon.

@alanhamlett
Copy link
Member

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
Copy link
Author

sisou commented Mar 24, 2015

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
Copy link
Author

sisou commented Mar 24, 2015

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 sisou closed this as completed Mar 24, 2015
@sisou
Copy link
Author

sisou commented Mar 24, 2015

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
Copy link
Member

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

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

2 participants