作者Pear888 (皮尔掰)
看板Python
标题[问题] pydrive 问题
时间Mon Oct 15 21:25:20 2018
不好意思想请教各位大大
小弟在heroku架了一个server来接收linebot的图片讯息
接收到的图片想直接存到google drive
在接收方面没有问题
从line获得的图片内容是class 'bytes'的型态
把这个内容丢到pydrive的函式 SetContentString 却出现 AttributeError: 'bytes' ob
ject has no attribute 'encode'
P.S. 这是SetContentString的函式
self.content = io.BytesIO(content.encode(encoding))
我尝试用另一个方式
gfile.content = message_content
来传送bytes形态的图片,却出现 AttributeError: bytes object has no attribute se
ek
小弟之前都是在本地端用setcontentfile的方式以档案上传,不知道在伺服器端如何以不
是档案的方式传送,在猜是不是要encode或decode的方式解决问题,恳请高手解答!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 223.140.226.138
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1539609923.A.061.html
1F:推 ckc1ark: gfile.content = io.BytesIO(message_content) 这样呢 10/15 22:41
2F:→ Pear888: 可以!感谢!刚刚查了一下原来BytesIO就是在记忆体写Byte 10/15 23:14
3F:→ Pear888: s且回传的本就是Bytes没有编码的问题 谢谢! 10/15 23:14