Kaynağa Gözat

[raz] Raz signed request proto call expecting bytes for Py3 (#3120)

Harsh Gupta 2 yıl önce
ebeveyn
işleme
0ceb87554f

+ 5 - 0
desktop/core/src/desktop/lib/raz/raz_client.py

@@ -250,6 +250,11 @@ class RazClient(object):
       "http_method: {%s}, headers: {%s}, parameters: {%s}, endpoint: {%s}, resource_path: {%s}, content_to_sign: {%s}" %
       (method, headers, allparams, endpoint, resource_path, data)
     )
+
+    # Raz signed request proto call expects data as bytes instead of str for Py3.
+    if sys.version_info[0] > 2 and data is not None and not isinstance(data, bytes):
+      data = data.encode()
+
     raz_req = raz_signer.SignRequestProto(
         endpoint_prefix=self.service_params['endpoint_prefix'],
         service_name=self.service_params['service_name'],

+ 2 - 2
desktop/libs/aws/src/aws/s3/s3connection.py

@@ -98,7 +98,7 @@ class RazS3Connection(SignedUrlS3Connection):
     3. return self._mexe(requests)
   """
 
-  def make_request(self, method, bucket='', key='', headers=None, data=b'',
+  def make_request(self, method, bucket='', key='', headers=None, data='',
                     query_args=None, sender=None, override_num_retries=None,
                     retry_handler=None):
 
@@ -139,7 +139,7 @@ class RazS3Connection(SignedUrlS3Connection):
     url = 'https://%(host)s%(path)s' % {'host': host, 'path': path}
 
     # Do not send the xml data for signing for upload operation
-    xml_data = b'' if query_args and 'uploadId=' in query_args else data
+    xml_data = '' if query_args and 'uploadId=' in query_args else data
 
     raz_headers = self.get_signed_url(action=method, url=url, headers=headers, data=xml_data)
     LOG.debug('Raz returned those headers: %s' % raz_headers)

+ 1 - 1
desktop/libs/aws/src/aws/s3/s3connection_test.py

@@ -85,7 +85,7 @@ class TestRazS3Connection():
           http_request.headers
         )
         assert_equal({}, http_request.params)
-        assert_equal(b'', http_request.body)
+        assert_equal('', http_request.body)
 
 
 class TestSelfSignedUrlS3Connection():