atom-community / ide-python

Python language support for Atom-IDE :atom: :snake:
https://atom.io/packages/ide-python
Other
237 stars 39 forks source link

Uncaught Error: Header must provide a Content-Length property. #106

Open jasonkuhrt opened 6 years ago

jasonkuhrt commented 6 years ago

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.26.1 x64 Electron: 1.7.11 OS: Mac OS X 10.13.4 Thrown From: ide-python package 0.9.2

Stack Trace

Uncaught Error: Header must provide a Content-Length property.

At /Users/jasonkuhrt/.atom/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:200

Error: Header must provide a Content-Length property.
    at StreamMessageReader.onData (/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:200:27)
    at /packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:185:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at Pipe.onread (net.js:560:20)

Commands

  2x -6:02.3.0 pane:show-previous-item (input.hidden-input)
     -5:58.6.0 vim-mode-plus:find (input.hidden-input)
  2x -5:58.2.0 vim-mode-plus:move-to-pair (input.hidden-input)
     -5:43.2.0 vim-mode-plus:move-to-first-character-of-line (input.hidden-input)
     -5:36.8.0 vim-mode-plus:insert-above-with-newline (input.hidden-input)
     -5:36.1.0 exit-insert-mode-if-preceded-by-k (input.hidden-input)
     -5:36.1.0 vim-mode-plus:activate-normal-mode (atom-text-editor.editor.vim-mode-plus.is-focused.insert-mode)
  2x -5:36 vim-mode-plus:delete (input.hidden-input)
     -5:35.7.0 vim-mode-plus:move-up (input.hidden-input)
     -5:35.4.0 vim-mode-plus:move-down (input.hidden-input)
     -5:35.3.0 vim-mode-plus:move-to-end-of-word (input.hidden-input)
     -5:35.1.0 vim-mode-plus:move-down (input.hidden-input)
     -5:34.6.0 vim-mode-plus:move-to-first-character-of-line (input.hidden-input)
  4x -5:33.9.0 vim-mode-plus:move-down (input.hidden-input)
     -5:30.9.0 core:save (input.hidden-input)
  2x -0:15.6.0 github:discard-changes-in-selected-files (span.github-FilePatchListView-path)

Non-Core Packages

asciidoc-assistant 0.2.2 
asciidoc-image-helper 1.0.0 
asciidoc-preview 2.11.0 
atom-autocomplete-php 0.25.6 
atom-beautify 0.32.2 
atom-ide-ui 0.11.1 
atom-ternjs 0.18.3 
atom-typescript 12.4.1 
atomatigit 1.5.5 
auto-detect-indentation 1.3.0 
auto-update-packages 1.0.1 
autocomplete-asciidoc 0.1.2 
autocomplete-haskell 1.0.1 
autocomplete-json 5.5.2 
autocomplete-modules 2.0.0 
busy-signal 1.4.3 
color-picker 2.3.0 
docblockr 0.13.7 
docker 0.8.0 
dockerletion 0.2.0 
flow-ide 1.11.0 
gist-it 0.9.2 
haskell-ghc-mod 2.2.3 
highlight-selected 0.13.1 
hyperclick 0.0.0 
ide-haskell 2.3.1 
ide-haskell-cabal 2.2.0 
ide-haskell-hasktags 0.0.15 
ide-haskell-repl 0.8.0 
ide-json 0.2.1 
ide-python 0.9.2 
ide-yaml 0.4.3 
intentions 1.1.5 
js-hyperclick 1.13.0 
language-apache 1.8.0 
language-asciidoc 1.11.0 
language-diff 0.7.0 
language-docker 1.1.8 
language-elm 1.5.0 
language-env 0.2.0 
language-haskell 1.17.6 
language-jade 0.7.3 
language-protobuf 0.7.1 
language-purescript 0.8.3 
language-terraform 0.8.1 
language-viml 1.1.8 
language-vue 0.23.1 
linter 2.2.0 
linter-coffeelint 2.0.0 
linter-docker 0.3.2 
linter-eslint 8.4.1 
linter-flow 5.6.1 
linter-hlint 2.0.0 
linter-jsonlint 1.3.0 
linter-php 1.5.1 
linter-pylama 0.9.5 
linter-shellcheck 1.4.7 
linter-tslint 1.9.1 
linter-ui-default 1.7.1 
nucleus-dark-ui 0.12.3 
pigments 0.40.2 
prettier-atom 0.53.0 
project-manager 3.3.5 
seti-syntax 1.1.3 
Sublime-Style-Column-Selection 1.7.4 
sync-settings 0.8.6 
todo-show 2.3.0 
vim-mode-plus 1.32.0 
wordcount 2.10.4 
Zen 0.18.0 
thedrow commented 6 years ago

This is extremely annoying. Can someone provides some insights on how to fix this?

thedrow commented 6 years ago

It seems like ide-rust were the only ones to resolve exactly this issue (See https://github.com/mehcode/atom-ide-rust/issues/66). The root cause was the language server itself. See https://github.com/rust-lang/rust/issues/48816.

lgeiger commented 6 years ago

@thedrow Thanks a lot for investigating!

Looks like we either have to fix the language server or start using IPC instead of stdio.

lgeiger commented 6 years ago

@thedrow @jasonkuhrt What's the output if you run pyls -vvv from the command line?

jasonkuhrt commented 6 years ago
❯ pyls -vvv
2018-05-25 00:20:09,565 UTC - INFO - pyls.python_ls - Starting PythonLanguageServer IO language server
_

?

thedrow commented 6 years ago

Same as @jasonkuhrt

lgeiger commented 6 years ago

The output looks fine. Are errors thrown after executing specific steps or are they present right after the startup?

Could you enable debug messages by executing atom.config.set('core.debugLSP', true) in the Developer Tools Console and post a screenshot of the console output when this issue occurs? You might need to restart Atom in order to see the debug messages.

Please also make sure to use the latest version of pyls. You can upgrade it via:

pip install 'python-language-server[all]' --upgrade
thedrow commented 6 years ago

Errors are presented at startup.

I did enable it & restarted and got:

/home/omer/.atom/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:200 Uncaught Error: Header must provide a Content-Length property.
    at StreamMessageReader.onData (/home/omer/.atom/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:200)
    at Socket.<anonymous> (/home/omer/.atom/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:185)
    at emitOne (events.js:96)
    at Socket.emit (events.js:191)
    at readableAddChunk (_stream_readable.js:178)
    at Socket.Readable.push (_stream_readable.js:136)
    at Pipe.onread (net.js:560)

And that's it. No extra logs :(

marvolo3d commented 6 years ago

Ran into this exact problem too. Rolled back to 0.10.0 and its working fine again:

apm remove ide-python
apm install ide-python@0.10.0
TrilceAC commented 6 years ago

I have two different virtualenvs, one for each of two different projects. I install the dependencies that the packages have at each virtualenv, so that atom is aware of the actual interpreter and environment intended to run my code. I do it to be able to navigate through code, or debug directly in atom.

I was consistently having this problem when launching atom from one of the virtualenvs but not when it was lauched from the other. Therefore, I decided to compare packages of both envs. I observed that in the faulty one I had pyls-mypy-0.1.3 installed, whereas it is not in the other one. I have just decided to remove this package and python-ide has begun to work properly.

Sorry if I do something wrong. I'm really newbie with atom.

Hope it helps!

harpaj commented 6 years ago

Removing pyls-mypy worked for me. Would still be great to be able to use it!

davidtreynolds commented 5 years ago

I downgraded ide-python as per @marvolo3d and the error has stopped appearing.

mkschulze commented 5 years ago

Any new insights here? i'm also running into the exact same issue, reproducable 100%.

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.31.2 x64 Electron: 2.0.7 OS: Mac OS X 10.13.6 Thrown From: ide-python package 1.0.0

Stack Trace

Uncaught Error: Header must provide a Content-Length property.

At /Users/irre/.atom/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:200

Error: Header must provide a Content-Length property.
    at StreamMessageReader.onData (/packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:200:27)
    at /packages/ide-python/node_modules/vscode-jsonrpc/lib/messageReader.js:185:19)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

Commands

     -1:09.5.0 editor:newline (input.hidden-input)
     -1:04.0 core:save (input.hidden-input)

Non-Core Packages

atom-beautify 0.33.4 
atom-clock 0.1.16 
atom-ide-debugger-python 0.7.3 
atom-ide-ui 0.13.0 
atom-python-run 0.9.7 
atom-python-virtualenv 1.0.2 
autoclose-html 0.23.0 
autocomplete-python 1.10.12 
autumn-highlighter-syntax 1.13.0 
browser-plus 0.0.98 
busy-signal 1.4.3 
color-picker 2.3.0 
data-atom 0.29.1 
emmet 2.4.3 
fancy-bracket-matcher 2.1.0 
file-icons 2.1.25 
fold-comments 0.6.0 
fonts 3.1.0 
git-plus 8.1.0 
highlight-line 0.12.0 
highlight-selected 0.14.0 
Hydrogen 2.6.0 
hydrogen-launcher 1.2.2 
hydrogen-python 0.0.7 
ide-python 1.0.0 
intentions 1.1.5 
kite 0.111.0 
language-graql 0.5.0 
linter 2.2.0 
linter-python 3.1.2 
linter-ui-default 1.7.1 
minimap 4.29.9 
minimap-pigments 0.2.2 
open-recent 5.0.0 
pigments 0.40.2 
python-debugger 0.2.0 
python-tools 0.6.9 
script 3.18.1 
sync-settings 0.8.6 
tag 0.5.0 
todo-show 2.3.2 
lgeiger commented 5 years ago

I'll have time to take a look next week. In the meantime I'm very happy to take contributions.

randomstuff commented 5 years ago

This is a problem of the server (pyls-mypy) not of the consumer. Here's the stdout of pyls (sudo sysdig -s6000 'proc.cmdline="python -m pyls"' -c stdout):

Content-Length: 43
Content-Type: application/vscode-jsonrpc; charset=utf8

{"jsonrpc": "2.0", "id": 5, "result": null}
:1:1: error: Cannot find module named 'cryptography.hazmat.primitives'
:1:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
:2:1: error: Cannot find module named 'cryptography.hazmat.primitives.kdf.hkdf'
:3:1: error: Cannot find module named 'cryptography.hazmat.backends.openssl'
:4:1: error: Cannot find module named 'cryptography.hazmat.primitives.ciphers'
:11:1: error: Cannot find module named 'filetype'

If you look closely some mypy error logging ends up in the process stdout which breaks the protocol.

AFAIU, this happens because mypy API currently works by temporarily overriding sys.stdout and sys.stde'rr which is not thread-safe:

def _run(f: Callable[[], None]) -> Tuple[str, str, int]:
    old_stdout = sys.stdout
    new_stdout = StringIO()
    sys.stdout = new_stdout

    old_stderr = sys.stderr
    new_stderr = StringIO()
    sys.stderr = new_stderr

    try:
        f()
        exit_status = 0
    except SystemExit as system_exit:
        exit_status = system_exit.code
    finally:
        sys.stdout = old_stdout
        sys.stderr = old_stderr

    return new_stdout.getvalue(), new_stderr.getvalue(), exit_status

def run(args: List[str]) -> Tuple[str, str, int]:
    # Lazy import to avoid needing to import all of mypy to call run_dmypy
    from mypy.main import main
    return _run(lambda: main(None, args=args))

I'm reporting the bug to pyls-mypy.

hoelzlmanuel commented 5 years ago

I had the same problem. However, setting Python Executable from python to python3 resolved the issue for me.

programmerjake commented 5 years ago

probably related: https://github.com/lgeiger/ide-python/issues/162 https://github.com/rust-lang/atom-ide-rust/issues/125

malarinv commented 5 years ago

It doesn't happen if I move the ~/.config/pycodestyle to the project root.

VictorSuarezL commented 4 years ago

@hoelzlmanuel Could you please elaborate more on your comment? As it seems to be a good way of fixing this issue. Are you creating an alias in the shell?