shengwubin opened a new pull request, #1796: URL: https://github.com/apache/libcloud/pull/1796
## Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue ### Environment ``` Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy Python: 3.9.12 ``` ``` pip install apache-libcloud # apache-libcloud-3.6.1 ``` ### Description ```python from libcloud.storage.providers import get_driver from libcloud.storage.types import Provider key='your key' secret='your secret' oss_endpoint='oss-cn-hangzhou.aliyuncs.com' oss_region='cn-hangzhou' bucket_name='your bucket' source='/path/to/source' target='/path/to/target' cls = get_driver(Provider.ALIYUN_OSS) driver = cls(key, secret, host=oss_endpoint, region=oss_region) container=driver.get_container(bucket_name) obj=container.upload_object(source, target) print(obj) ``` The above code will have below output on my computer: ```python Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/anaconda3/lib/python3.9/site-packages/libcloud/storage/base.py", line 203, in upload_object return self.driver.upload_object( File "/anaconda3/lib/python3.9/site-packages/libcloud/storage/drivers/oss.py", line 454, in upload_object return self._put_object( File "/anaconda3/lib/python3.9/site-packages/libcloud/storage/drivers/oss.py", line 642, in _put_object server_hash = headers["etag"].replace('"', "") KeyError: 'etag' ``` ### Changes The problem here is that when sending uploading requests to OSS, the bucket name cannot be inserted into the url, for example, the final url should be like `https://your-bucket.oss-cn-hangzhou.aliyuncs.com/...`, but the current code will send a request with `https://oss-cn-hangzhou.aliyuncs.com/...`, then the bucket information will not be included in the `upload_object` function. Below is what I change: 1. Add a `container` argument in the `_upload_object` function. 2. Use `.upper()` when comparing the `data_hash` and `server_hash` to avoid hash mismatch 3. Add a `container` argument in the `Connection` class to avoid argument errors for other cloud storages Chinese document: [https://help.aliyun.com/document_detail/31978.html?spm=a2c4g.11186623.0.0.140a26c0FKn8dD](https://help.aliyun.com/document_detail/31978.html?spm=a2c4g.11186623.0.0.140a26c0FKn8dD) ### Status done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@libcloud.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org