Skip to content

Python SDK client is not encoding "/" character in parameters #748

Open
@xdobiasl

Description

@xdobiasl

Our QA are getting error 404 when they want to access object with a slash "/" (aka directory in objectstorage) via queryservice (not yet released).
But when accessing the same object via OCI Java SDK, it works correctly.

We realized that the problem is that the parameter is not URL-encoded by Python OCI SDK client, or it is encoded, but without "/" character.

In the base_client.py, there is a line calling this function to URL-encode parameters:

                replacement = six.moves.urllib.parse.quote(str(self.to_path_value(v)))

The problem is that function to URL encode parameters ignore "/" character by default (so it can be used on URL-like strings). See docs: https://docs.python.org/3/library/urllib.parse.html

urllib.parse.quote(string, safe='/', encoding=None, errors=None)
Replace special characters in string using the %xx escape. Letters, digits, and the characters '_.-~' are never quoted. By default, this function is intended for quoting the path section of a URL. The optional safe parameter specifies additional ASCII characters that should not be quoted — its default value is '/'.

We think that the line above should be fixed like this - to encode all chars, including "/":

                replacement = six.moves.urllib.parse.quote(str(self.to_path_value(v)), safe='')

Illustration of our problem (see "url" values in the requests):

  • We get error for object "vector/0001.parquet":
$ ./get-schema.py
Get schema for Object oraclebigdatadb/test-bucket-parquet/vector/0001.parquet
Sending request......
{ 'body': None,
  'enforce_content_headers': True,
  'header': { 'accept': 'application/json',
              'content-type': 'application/json',
              'opc-client-info': 'Oracle-PythonSDK/2.149.2+preview.1.178',
              'opc-client-retries': 'true',
              'opc-request-id': '2032EC3DDEB94E08B6E966B22EC2E9B8',
              'user-agent': 'Oracle-PythonSDK/2.149.2+preview.1.178 (python '
                            '3.10.12; x86_64-Linux)'},
  'method': 'POST',
  'query_params': None,
  'response_type': 'ObjectSchema',
  'url': 'https://query.sql.us-ashburn-1.oci.oraclecloud.com/20210831/projects/ocid1.queryserviceproject.oc1.iad.amaaaaaayrywvyyaoa3pka3cmnzbtaziiifo3evmgdzbltu6o3ky5vakyg4a/n/oraclebigdatadb/b/test-bucket-parquet/o/vector/0001.parquet/actions/getObjectSchema'}

Receiving response......
{ 'header': { 'Content-Length': '111',
              'Content-Type': 'application/json',
              'Date': 'Thu, 27 Mar 2025 17:52:02 GMT',
              'Strict-Transport-Security': 'max-age=31536000; '
                                           'includeSubDomains;',
              'opc-request-id': '2032EC3DDEB94E08B6E966B22EC2E9B8/8169B56501935D3576428A8343B97912/540299E593A8BEEF29A193812FCED43A'},
  'reason': 'Not Found',
  'status_code': 404,
  'url': 'https://query.sql.us-ashburn-1.oci.oraclecloud.com/20210831/projects/ocid1.queryserviceproject.oc1.iad.amaaaaaayrywvyyaoa3pka3cmnzbtaziiifo3evmgdzbltu6o3ky5vakyg4a/n/oraclebigdatadb/b/test-bucket-parquet/o/vector/0001.parquet/actions/getObjectSchema'}

Error:  {'target_service': 'query', 'status': 404, 'code': 'NotAuthorizedOrNotFound', 'opc-request-id': '2032EC3DDEB94E08B6E966B22EC2E9B8/8169B56501935D3576428A8343B97912/540299E593A8BEEF29A193812FCED43A', 'message': 'Authorization failed or requested resource not found.', 'operation_name': 'get_object_schema', 'timestamp': '2025-03-27T17:52:02.763638+00:00', 'client_version': 'Oracle-PythonSDK/2.149.2+preview.1.178', 'request_endpoint': 'POST https://query.sql.us-ashburn-1.oci.oraclecloud.com/20210831/projects/ocid1.queryserviceproject.oc1.iad.amaaaaaayrywvyyaoa3pka3cmnzbtaziiifo3evmgdzbltu6o3ky5vakyg4a/n/oraclebigdatadb/b/test-bucket-parquet/o/vector/0001.parquet/actions/getObjectSchema', 'logging_tips': 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/tools/python/latest/logging.html for ways to log the request/response details.', 'troubleshooting_tips': 'See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_404__404_notauthorizedornotfound for more information about resolving this error. If you are unable to resolve this query issue, please contact Oracle support and provide them this full error message.'}
  • When we encode "/" to "%2f" then it works:
$ ./get-schema.py
Get schema for Object oraclebigdatadb/test-bucket-parquet/vector%2f0001.parquet
Sending request......
{ 'body': None,
  'enforce_content_headers': True,
  'header': { 'accept': 'application/json',
              'content-type': 'application/json',
              'opc-client-info': 'Oracle-PythonSDK/2.149.2+preview.1.178',
              'opc-client-retries': 'true',
              'opc-request-id': 'BB74D30DFED84F5195EBCA29EA6DC5B5',
              'user-agent': 'Oracle-PythonSDK/2.149.2+preview.1.178 (python '
                            '3.10.12; x86_64-Linux)'},
  'method': 'POST',
  'query_params': None,
  'response_type': 'ObjectSchema',
  'url': 'https://query.sql.us-ashburn-1.oci.oraclecloud.com/20210831/projects/ocid1.queryserviceproject.oc1.iad.amaaaaaayrywvyyaoa3pka3cmnzbtaziiifo3evmgdzbltu6o3ky5vakyg4a/n/oraclebigdatadb/b/test-bucket-parquet/o/vector%252f0001.parquet/actions/getObjectSchema'}

Receiving response......
{ 'header': { 'Content-Length': '1604',
              'Content-Type': 'application/json',
              'Date': 'Thu, 27 Mar 2025 17:57:45 GMT',
              'Opc-Request-Id': 'BB74D30DFED84F5195EBCA29EA6DC5B5/411A75682AFFD17FB165DDC0C228E476/070c11d228470e1329fb8648fa7807fb',
              'Strict-Transport-Security': 'max-age=31536000; '
                                           'includeSubDomains;',
              'X-Content-Type-Options': 'nosniff'},
  'reason': 'OK',
  'status_code': 200,
  'url': 'https://query.sql.us-ashburn-1.oci.oraclecloud.com/20210831/projects/ocid1.queryserviceproject.oc1.iad.amaaaaaayrywvyyaoa3pka3cmnzbtaziiifo3evmgdzbltu6o3ky5vakyg4a/n/oraclebigdatadb/b/test-bucket-parquet/o/vector%252f0001.parquet/actions/getObjectSchema'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    SDKIssue pertains to the SDK itself and not specific to any service

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions