如何通过Dropbox上传图片与python
问题描述:
我已经尝试了多种方式上传图片在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'>
是不是我不明白?
答
只是使用
dbx.files_upload(imageFile.read(), '/' + o)
字节数组和字节不相等。自从在''rb“中打开后,传入f而不是'b',并且您已经读取了文件中的内容以'f'将它作为二进制内容。 – Pythonista