From cc55a182b878d78f92aba259c067d47ab1d01e5b Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Thu, 4 Feb 2021 17:17:38 -0800 Subject: [PATCH] fix: body encoding for rest transport (#768) Basically just replace `json` argument with `data` Apparently, the `json` parameter in requests.Session.request() method does not expect JSON string, but expects python dictionary instead, which is not intuitive and does not even match the documentation of the method: https://github.com/psf/requests/blob/master/requests/sessions.py#L483. At the same time in the Quickstart, it is explicitly said that `json` parameter was added in version `2.4.2` and expects python `dict`, while `data` argument can process raw encoded json string. --- .../%name_%version/%sub/services/%service/transports/rest.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index 060e5d0744..1341571e48 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -198,7 +198,7 @@ class {{ service.name }}RestTransport({{ service.name }}Transport): {% if not method.void %}response = {% endif %}self._session.{{ method.http_opt['verb'] }}( url {%- if 'body' in method.http_opt %}, - json=body, + data=body, {%- endif %} )