ycm-core / ycmd

A code-completion & code-comprehension server
https://ycm-core.github.io/ycmd/
GNU General Public License v3.0
1.69k stars 765 forks source link

Argument of type 'NoneType' ist not iterable: empty message body #1684

Closed Belserich closed 1 year ago

Belserich commented 1 year ago

Hey there, I downloaded ycmd and started the server with a minimal options file (just specified the HMAC). After that I made a request via curl to /completions. The message body is

{
  "line_num": 32, 
  "column_num": 8, 
  "filepath": "path/to/file", 
  "file_data": 
  { 
    "filetypes": [ "string" ], 
    "contents": "" 
  }
}

The signal was accepted, meaning hmac validation passed successfully. I'm getting this error now:

Traceback (most recent call last):
  File "/home/belserich/.local/src/ycmd/third_party/bottle/bottle.py", line 876, in _handle
    return route.call(**args)
  File "/home/belserich/.local/src/ycmd/third_party/bottle/bottle.py", line 1756, in wrapper
    rv = callback(*a, **ka)
  File "/home/belserich/.local/src/ycmd/ycmd/watchdog_plugin.py", line 97, in wrapper
    return callback( *args, **kwargs )
  File "/home/belserich/.local/src/ycmd/ycmd/hmac_plugin.py", line 63, in wrapper
    body = callback( *args, **kwargs )
  File "/home/belserich/.local/src/ycmd/ycmd/handlers.py", line 108, in GetCompletions
    request_data = RequestWrap( request.json )
  File "/home/belserich/.local/src/ycmd/ycmd/request_wrap.py", line 34, in __init__
    EnsureRequestValid( request )
  File "/home/belserich/.local/src/ycmd/ycmd/request_validation.py", line 26, in EnsureRequestValid
    missing = { x for x in required_fields if x not in request_json }
  File "/home/belserich/.local/src/ycmd/ycmd/request_validation.py", line 26, in <setcomp>
    missing = { x for x in required_fields if x not in request_json }
TypeError: argument of type 'NoneType' is not iterable

I tried manually debugging the problem. It is that request_json in line 24 of request_validation.py is None. How come? What am I doing wrong?

puremourning commented 1 year ago

What am I doing wrong?

Not sure because you didn't explicitly state what exactly you did. Could you paste the exact curl command you used?

It looks on the face of it like you missed like the content-type header or didn't post or something.

Belserich commented 1 year ago

The curl command is part of a shell script but it goes like curl -v -i -X $2 -H "X-Ycm-Hmac:$encoded_hmac" -d "$4" http://localhost:$1"$3" I call this like ./request $port POST /completion "$data"

$encoded_hmac must be correct since the message is being validated. You mentioned content-type headers. I didnt specify them, these would be "application/json" right? It's my first time using http for anything

Belserich commented 1 year ago

Okay, I solved the issue by adding the corrent content-type-header (which is application/json)