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 04:23:36 UTC
[GitHub] [libcloud] shengwubin opened a new pull request, #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
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-unsubscribe@libcloud.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [libcloud] asfgit merged pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit merged PR #1796:
URL: https://github.com/apache/libcloud/pull/1796
--
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] Kami commented on a diff in pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by GitBox <gi...@apache.org>.
Kami commented on code in PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#discussion_r1070613501
##########
libcloud/common/base.py:
##########
@@ -527,6 +527,7 @@ def request(
stream=False,
json=None,
retry_failed=None,
+ container=None,
Review Comment:
Thanks - this new approach indeed looks much better and safer :)
--
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] Kami commented on a diff in pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by GitBox <gi...@apache.org>.
Kami commented on code in PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#discussion_r1045101820
##########
libcloud/common/base.py:
##########
@@ -527,6 +527,7 @@ def request(
stream=False,
json=None,
retry_failed=None,
+ container=None,
Review Comment:
Overall, the changes except this one look good to me.
I don't think we should add ``container`` argument this function since it's a generic function not tied to any specific API so we should create a dependency on the storage API / container argument here.
--
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 #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by "shengwubin (via GitHub)" <gi...@apache.org>.
shengwubin commented on PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#issuecomment-1399397932
> Looks like this still needs more work since tests are now failing with:
>
> ```shell
> > result_dict = self._upload_object(
> object_name=object_name,
> content_type=content_type,
> request_path=request_path,
> request_method=method,
> headers=headers,
> file_path=file_path,
> stream=stream,
> container=container,
> )
> E TypeError: upload_file() got an unexpected keyword argument 'container'
> ```
@Kami I add `container=container` to the oss storage test cases. The issue here is that when replacing the original `_upload_object` with `upload_file`, the argument `container` is missing
--
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] Kami commented on pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by GitBox <gi...@apache.org>.
Kami commented on PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#issuecomment-1383172735
Looks like this still needs more work since tests are now failing with:
```bash
> result_dict = self._upload_object(
object_name=object_name,
content_type=content_type,
request_path=request_path,
request_method=method,
headers=headers,
file_path=file_path,
stream=stream,
container=container,
)
E TypeError: upload_file() got an unexpected keyword argument 'container'
```
--
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] Kami commented on a diff in pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by GitBox <gi...@apache.org>.
Kami commented on code in PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#discussion_r1045102148
##########
libcloud/common/base.py:
##########
@@ -527,6 +527,7 @@ def request(
stream=False,
json=None,
retry_failed=None,
+ container=None,
Review Comment:
Also, did you push all the changes? Since I don't see ``container`` argument you added in a bunch of places actually being used (or did I miss something)?
--
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] Kami commented on pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by "Kami (via GitHub)" <gi...@apache.org>.
Kami commented on PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#issuecomment-1407469414
Merged into trunk. Thanks.
--
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 a diff in pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by GitBox <gi...@apache.org>.
shengwubin commented on code in PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#discussion_r1064235523
##########
libcloud/common/base.py:
##########
@@ -527,6 +527,7 @@ def request(
stream=False,
json=None,
retry_failed=None,
+ container=None,
Review Comment:
The reason I changed this line is to avoid influencing other storage providers, for example, s3.
My previous changes were not a good idea because they added several lines into `libcloud/storage/base.py` so that other providers' upload functions will throw exceptions.
I have reverted all the changes that lead to this situation, and the new solution will only affect `libcloud/storage/drivers/oss.py`. The possible side effect is that if the method `_upload_object` of class `StorageDriver` in `libcloud/storage/base.py` changes, the OSS-related method also needs to be changed if necessary.
--
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] codecov-commenter commented on pull request #1796: Fix Aliyun OSS storage upload_object KeyError: 'ETag' issue
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #1796:
URL: https://github.com/apache/libcloud/pull/1796#issuecomment-1407439386
# [Codecov](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#1796](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7c460b8) into [trunk](https://codecov.io/gh/apache/libcloud/commit/d8f0d3a9fbd8c1edd2d116ccfcaff1471fdb324e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d8f0d3a) will **decrease** coverage by `0.01%`.
> The diff coverage is `43.75%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1796/graphs/tree.svg?width=650&height=150&src=pr&token=PYoduksh69&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## trunk #1796 +/- ##
==========================================
- Coverage 83.40% 83.40% -0.01%
==========================================
Files 403 403
Lines 88236 88251 +15
Branches 9344 9347 +3
==========================================
+ Hits 73596 73602 +6
- Misses 11459 11465 +6
- Partials 3181 3184 +3
```
| [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [libcloud/test/storage/test\_oss.py](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvdGVzdC9zdG9yYWdlL3Rlc3Rfb3NzLnB5) | `95.60% <ø> (ø)` | |
| [libcloud/storage/drivers/oss.py](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvc3RvcmFnZS9kcml2ZXJzL29zcy5weQ==) | `69.82% <43.75%> (-1.19%)` | :arrow_down: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d8f0d3a...7c460b8](https://codecov.io/gh/apache/libcloud/pull/1796?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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