[問題] pydrive 問題

作者: Pear888 (皮爾掰)   2018-10-15 21:25:20
不好意思想請教各位大大
小弟在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的方式解決問題,懇請高手解答!
作者: ckc1ark (偽物)   2018-10-15 22:41:00
gfile.content = io.BytesIO(message_content) 這樣呢
作者: Pear888 (皮爾掰)   2018-10-15 23:14:00
可以!感謝!剛剛查了一下原來BytesIO就是在記憶體寫Bytes且回傳的本就是Bytes沒有編碼的問題 謝謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com