CodexBloom - Programming Q&A Platform

OCI Object Storage Access Error with Pre-signed URLs in Python SDK

👀 Views: 313 đŸ’Ŧ Answers: 1 📅 Created: 2025-09-06
OCI Object Storage Python SDK Cloud

I'm experimenting with I'm performance testing and Hey everyone, I'm running into an issue that's driving me crazy. I'm stuck on something that should probably be simple... I'm encountering a '403 Forbidden' error when trying to upload a file to OCI Object Storage using pre-signed URLs generated with the Oracle Cloud Infrastructure Python SDK. My setup includes using SDK version `2.33.0` with Python `3.8`. Here's the code I'm using to generate the pre-signed URL: ```python import oci config = oci.config.from_file() # Load the config from file object_storage_client = oci.object_storage.ObjectStorageClient(config) bucket_name = 'my_bucket' namespace = 'my_namespace' object_name = 'test_file.txt' # Generate pre-signed URL url = object_storage_client.generate_presigned_url( 'put_object', namespace_name=namespace, bucket_name=bucket_name, object_name=object_name ) print(url) ``` After generating the URL, I use the following code to upload the file: ```python import requests file_data = open('test_file.txt', 'rb').read() response = requests.put(url, data=file_data) print(response.status_code, response.text) ``` The URL and the upload request seem fine but I keep getting a 403 error, which suggests I might not have the correct permissions. I've checked the bucket policy and ensured that the user has `OBJECT_WRITE` permissions. Additionally, I verified that the `namespace` and `bucket_name` are correct. Interestingly, if I try to upload a file directly using the SDK's `put_object` method, it works perfectly, which leads me to believe the issue lies with the pre-signed URL. Is there a specific permission or configuration I'm missing for the pre-signed URL to work properly? Does anyone have experience with generating and using pre-signed URLs in OCI Object Storage? Thanks in advance! My development environment is macOS. What's the best practice here? For context: I'm using Python on Ubuntu 20.04. I'd love to hear your thoughts on this. I appreciate any insights!