[問題] pydrive 問題

看板Python作者 (皮爾掰)時間5年前 (2018/10/15 21:25), 編輯推噓1(102)
留言3則, 2人參與, 5年前最新討論串1/1
不好意思想請教各位大大 小弟在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://www.ptt.cc/bbs/Python/M.1539609923.A.061.html

10/15 22:41, 5年前 , 1F
gfile.content = io.BytesIO(message_content) 這樣呢
10/15 22:41, 1F

10/15 23:14, 5年前 , 2F
可以!感謝!剛剛查了一下原來BytesIO就是在記憶體寫Byte
10/15 23:14, 2F

10/15 23:14, 5年前 , 3F
s且回傳的本就是Bytes沒有編碼的問題 謝謝!
10/15 23:14, 3F
文章代碼(AID): #1Rn9L31X (Python)