看板 Python 關於我們 聯絡資訊
不好意思想請教各位大大 小弟在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
ckc1ark: gfile.content = io.BytesIO(message_content) 這樣呢 10/15 22:41
Pear888: 可以!感謝!剛剛查了一下原來BytesIO就是在記憶體寫Byte 10/15 23:14
Pear888: s且回傳的本就是Bytes沒有編碼的問題 謝謝! 10/15 23:14