0
我已經嘗試了多種方式上傳圖片在Python與Dropbox API,它非常複雜。如何通過Dropbox上傳圖片與python
bot.command(pass_context=True)
async def upload(ctx, *, message):
await bot.say("Downloading the file from the link, hang on...")
url = str(message)
wget.download(url)
await bot.say("Done. Now uploading it to Dropbox...")
o = os.path.basename(url)
with open(o, "rb") as imageFile:
f = imageFile.read()
b = bytearray(f)
dbx.files_upload(b, '/' + o)
由於files_upload需要字節,路徑我不知道如何去做。 我總是得到這個錯誤
TypeError: expected request_binary as binary type, got <class 'bytearray'>
是不是我不明白?
字節數組和字節不相等。自從在''rb「中打開後,傳入f而不是'b',並且您已經讀取了文件中的內容以'f'將它作爲二進制內容。 – Pythonista