使用Dropbox Python库下载文件

时间:2016-10-11 19:02:47

标签: python dropbox

环境:Windows 7,Visual Studio的Python工具,Python 2.7,Python包保管箱(6.9.0),Dropbox帐户的访问令牌

运行以下代码:

    import dropbox
    access_token = '<token value here>'
    dbx = dropbox.Dropbox(access_token)

    with open("C:\Test.txt", "w") as f:
        metadata, res = dbx.files_download(path="/Test.txt")
        f.write(res.content)

最后一行的错误如下:   &#34;没有可用的反汇编&#34;

我不理解错误不是Python开发人员..该文件是在本地计算机上创建的,但没有任何内容从dropbox文件下载到它中。

非常感谢任何帮助..谢谢

2 个答案:

答案 0 :(得分:0)

用于使用业务 API 下载 Dropbox 的 Python 代码:

def dropbox_file_download(access_token,dropbox_file_path,local_folder_name):
try:
    dropbox_file_name = dropbox_file_path.split('/')[-1]
    dropbox_file_path = '/'.join(dropbox_file_path.split('/')[:-1])
    dbx = dropbox.DropboxTeam(access_token)
    # get the team member id for common user
    members = dbx.team_members_list()
    for i in range(0,len(members.members)):
        if members.members[i].profile.name.display_name == logged_user_name:
            member_id = members.members[i].profile.team_member_id
            break
    # connect to dropbox with member id
    dbx = dropbox.DropboxTeam(access_token).as_user(member_id)
    # list all the files from the folder
    result = dbx.files_list_folder(dropbox_file_path, recursive=False)
    #  download given file from dropbox
    for entry in result.entries:
        if isinstance(entry, dropbox.files.FileMetadata):
            if entry.name == dropbox_file_name:
                dbx.files_download_to_file(local_folder_name+entry.name, entry.path_lower)
                return True
    return False
except Exception as e:
    print(e)
    return False

答案 1 :(得分:-1)

import dropbox
access_token = '**********************'
dbx = dropbox.Dropbox(access_token)
f = open("ABC.txt","w")                    
metadata,res = dbx.files_download("abc.txt")     //dropbox file path
f.write(res.content)