Repository: googleapis/google-cloud-python

Issue:
Use POST with Translate API
I try to translate a piece of text that's more than 2000 characters. The limit of a GET request to the translate API is 2000 characters. So my idea was to POST instead of GET, but that does not seem to be configurable, see https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/translate/google/cloud/translate_v2/client.py#L234 .

Is it possible to use POST with Translate?


Discussion:
Thanks for the report.  According to the [REST API docs](https://cloud.google.com/translate/docs/reference/translate), the `translate` API is *supposed* to be invoked with `POST`:  I am surprised that it works at all with `GET`.

However, that same API doc requires that all parameters to the `translate` method be passed in the query string, which means that the limit is probably not any different for `POST`.
This seems to be a limitation of the underlying API. There is not really anything the client libraries can do about this. Sorry. :-(
@tseaver Have you tried sending the query parameters in the body?
@lukesneeringer Our implementation is still contra-spec (sending a `GET` vs a `POST` request).
@dhermes I haven't poked at anything:  I just looked at the [`translate` API docs](https://cloud.google.com/translate/docs/reference/translate), which mandate query parameters and a body-less `POST` (absurd, I know).

Resolving patch:
diff --git a/translate/google/cloud/translate_v2/client.py b/translate/google/cloud/translate_v2/client.py
--- a/translate/google/cloud/translate_v2/client.py
+++ b/translate/google/cloud/translate_v2/client.py
@@ -231,7 +231,7 @@ def translate(self, values, target_language=None, format_=None,
             query_params.append(('model', model))
 
         response = self._connection.api_request(
-            method='GET', path='', query_params=query_params)
+            method='POST', path='', query_params=query_params)
 
         translations = response.get('data', {}).get('translations', ())
         if len(values) != len(translations):


Test patch:
diff --git a/translate/tests/unit/test_client.py b/translate/tests/unit/test_client.py
--- a/translate/tests/unit/test_client.py
+++ b/translate/tests/unit/test_client.py
@@ -249,7 +249,7 @@ def test_translate_bad_result(self):
         # Verify requested.
         self.assertEqual(len(conn._requested), 1)
         req = conn._requested[0]
-        self.assertEqual(req['method'], 'GET')
+        self.assertEqual(req['method'], 'POST')
         self.assertEqual(req['path'], '')
         query_params = [
             ('target', 'en'),
@@ -278,7 +278,7 @@ def test_translate_defaults(self):
         # Verify requested.
         self.assertEqual(len(conn._requested), 1)
         req = conn._requested[0]
-        self.assertEqual(req['method'], 'GET')
+        self.assertEqual(req['method'], 'POST')
         self.assertEqual(req['path'], '')
         query_params = [
             ('target', 'en'),
@@ -313,7 +313,7 @@ def test_translate_multiple(self):
         # Verify requested.
         self.assertEqual(len(conn._requested), 1)
         req = conn._requested[0]
-        self.assertEqual(req['method'], 'GET')
+        self.assertEqual(req['method'], 'POST')
         self.assertEqual(req['path'], '')
         query_params = [
             ('target', 'en'),
@@ -350,7 +350,7 @@ def test_translate_explicit(self):
         # Verify requested.
         self.assertEqual(len(conn._requested), 1)
         req = conn._requested[0]
-        self.assertEqual(req['method'], 'GET')
+        self.assertEqual(req['method'], 'POST')
         self.assertEqual(req['path'], '')
         query_params = [
             ('target', target_language),