You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by GitBox <gi...@apache.org> on 2022/11/05 02:15:33 UTC

[GitHub] [libcloud] shengwubin opened a new pull request, #1794: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue

shengwubin opened a new pull request, #1794:
URL: https://github.com/apache/libcloud/pull/1794

   ## 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
   
   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-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [libcloud] shengwubin closed pull request #1794: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue

Posted by GitBox <gi...@apache.org>.
shengwubin closed pull request #1794: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
URL: https://github.com/apache/libcloud/pull/1794


-- 
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-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [libcloud] shengwubin commented on pull request #1794: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue

Posted by GitBox <gi...@apache.org>.
shengwubin commented on PR #1794:
URL: https://github.com/apache/libcloud/pull/1794#issuecomment-1304398795

   This will influence other storage backends. Close this pull request to revise the code.


-- 
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-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org