diff --git a/python/ycm/client/base_request.py b/python/ycm/client/base_request.py index 73850034..7f609727 100644 --- a/python/ycm/client/base_request.py +++ b/python/ycm/client/base_request.py @@ -18,13 +18,13 @@ # along with YouCompleteMe. If not, see . import vim -import json import requests import urlparse from retries import retries from requests_futures.sessions import FuturesSession from ycm.unsafe_thread_pool_executor import UnsafeThreadPoolExecutor from ycm import vimsupport +from ycm.utils import ToUtf8Json from ycm.server.responses import ServerError, UnknownExtraConf _HEADERS = {'content-type': 'application/json'} @@ -89,7 +89,7 @@ class BaseRequest( object ): def SendRequest( data, handler, method, timeout ): if method == 'POST': return BaseRequest.session.post( _BuildUri( handler ), - data = json.dumps( data ), + data = ToUtf8Json( data ), headers = _HEADERS, timeout = timeout ) if method == 'GET': @@ -101,7 +101,7 @@ class BaseRequest( object ): def DelayedSendRequest( data, handler, method ): if method == 'POST': return requests.post( _BuildUri( handler ), - data = json.dumps( data ), + data = ToUtf8Json( data ), headers = _HEADERS ) if method == 'GET': return requests.get( _BuildUri( handler ), diff --git a/python/ycm/utils.py b/python/ycm/utils.py index 608b484f..308f9d59 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -24,6 +24,7 @@ import signal import functools import socket import stat +import json from distutils.spawn import find_executable import subprocess @@ -47,6 +48,10 @@ def ToUtf8IfNeeded( value ): return str( value ) +def ToUtf8Json( data ): + return ToUtf8IfNeeded( json.dumps( data, ensure_ascii = False ) ) + + def PathToTempDir(): tempdir = os.path.join( tempfile.gettempdir(), 'ycm_temp' ) if not os.path.exists( tempdir ):