tencentyun / cos-python-sdk Goto Github PK
View Code? Open in Web Editor NEW对象存储服务(Cloud Object Service)Python SDK使用说明
Home Page: https://www.qcloud.com/doc/product/227/3385
License: MIT License
对象存储服务(Cloud Object Service)Python SDK使用说明
Home Page: https://www.qcloud.com/doc/product/227/3385
License: MIT License
如果我添加一行
self._secret_key = str(self._secret_key)
这个错误会消失。
但是出现新的错误是:
'ascii' codec can't decode byte 0xe7 in position 2: ordinal not in range(128)
有些函数命名用驼峰法,有些又用下划线分隔法……应该统一成python的下划线分隔形式吧
按照sample.py里的upload整了好久,都不成功,最后仔细看源码发现参数顺序都是错的。
pip install qcloud_cos 后,文件已经 copy 到了系统目录里面,没办法再去修改 conf.py 了。多个项目也无法使用不同的配置。能否改变一下配置的方式?比如用 class 实现?
我在程序里处理好了一串文本流,那我怎样才能上传?
sdk报错:
TypeError: character mapping must return integer, None or unicode
Traceback (most recent call last):
File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
self.run()
File "./download_and_upload.py", line 140, in run
self.upload(data, msg)
File "./download_and_upload.py", line 118, in upload
result = cos_api.statFile(bucket, cos_path)
File "/usr/lib/python2.6/site-packages/qcloud_cos/cos.py", line 314, in statFile
return self.__stat(bucket, path)
File "/usr/lib/python2.6/site-packages/qcloud_cos/cos.py", line 327, in __stat
sign = auth.sign_more(bucket, expired)
File "/usr/lib/python2.6/site-packages/qcloud_cos/auth.py", line 62, in sign_more
return self.app_sign(bucket, '', expired)
File "/usr/lib/python2.6/site-packages/qcloud_cos/auth.py", line 51, in app_sign
bin = hmac.new(self._secret_key, plain_text, hashlib.sha1)
File "/usr/lib64/python2.6/hmac.py", line 133, in new
return HMAC(key, msg, digestmod)
File "/usr/lib64/python2.6/hmac.py", line 72, in __init__
self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode
`
主要原因:
python 2.6的hmac不支持unicode编码导致:
http://bugs.python.org/issue5285
解决方案:
传递给api的参数进行str处理:
cos_app_id = str(info['cos_app_id'])
cos_s_id = str(info['cos_s_id'])
cos_s_key = str(info['cos_s_key'])
bucket = str(info['cos_bucket'])
cos_api = qcloud_cos.Cos(cos_app_id, cos_s_id, cos_s_key)
result = cos_api.statFile(bucket, cos_path)
发现代码发生重大变化,以前的cos下直接调用函数即可,现在改成request了,建议合并到qcloud-api-sdk中,这个sdk是可以恢复以前的接口?
估计诸位心里也是知道的吧。
求更新,辛苦
非要写文件呢?
https://github.com/chandlerding/cos-python-sdk/commit/23180edd4f5775cbe972d823100192a8d78892c2
fix provided, requesting pull
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.