Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.8.1-权限错误:[Errno 13]权限被拒绝_Python_Windows_Permissions_Permission Denied - Fatal编程技术网

Python 3.8.1-权限错误:[Errno 13]权限被拒绝

Python 3.8.1-权限错误:[Errno 13]权限被拒绝,python,windows,permissions,permission-denied,Python,Windows,Permissions,Permission Denied,我正在尝试使用Python和Dropbox api将一些文件上传到Dropbox 这就是我目前所拥有的- import sys import dropbox import time from dropbox.files import WriteMode from dropbox.exceptions import ApiError, AuthError # Access dropboxToken dropboxToken = '<token>' localPath = '&l

我正在尝试使用Python和Dropbox api将一些文件上传到Dropbox

这就是我目前所拥有的-

import sys
import dropbox
import time

from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError


# Access dropboxToken
dropboxToken = '<token>'

localPath = '<local path in Downloads folder>'
uploadPath = '<dropbox path>'


# Uploads contents of localFile to Dropbox
def upload():
    with open(localPath, 'rb') as f:
        for file in localPath:
            # We use WriteMode=overwrite to make sure that the settings in the file
            # are changed on upload
            print('Uploading ' + localFile + ' to Dropbox location ' + uploadPath)
            try:
                dbx.files_upload(f.read(), uploadPath, mode=WriteMode('overwrite'))
            except ApiError as err:
                # This checks for the specific error where a user doesn't have enough Dropbox space quota to upload this file
                if (err.error.is_path() and
                        err.error.get_path().error.is_insufficient_space()):
                    sys.exit('ERROR: Cannot upload file; insufficient space.')
                elif err.user_message_text:
                    print(err.user_message_text)
                    sys.exit()
                else:
                    print(err)
                    sys.exit()

if __name__ == '__main__':
    print('Uploading file(s)...')
    # upload the files
    upload()

导入系统 导入dropbox 导入时间 从dropbox.files导入WriteMode 从dropbox.exceptions导入ApiError,AuthError #访问dropboxToken dropboxToken='' localPath='' 上传路径=“” #将本地文件的内容上载到Dropbox def upload(): 将open(localPath,'rb')作为f: 对于localPath中的文件: #我们使用WriteMode=overwrite来确保文件中的设置 #在上传时更改 打印('上载'+localFile+'到Dropbox位置'+uploadPath) 尝试: dbx.files\u upload(f.read(),uploadPath,mode=WriteMode('overwrite')) 除APIRERROR作为err外: #这将检查用户没有足够的Dropbox空间配额来上载此文件的特定错误 if(err.error.is_path()和 err.error.get_path().error.is_空间不足()): sys.exit('错误:无法上载文件;空间不足') elif err.user\u消息\u文本: 打印(错误用户\消息\文本) sys.exit() 其他: 打印(错误) sys.exit() 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': 打印('正在上载文件) #上传文件 上传() 无论何时运行它,我都会收到以下消息:
PermissionError:[Errno 13]权限被拒绝

我读过一些关于以管理员身份空闲运行、以管理员身份从命令行执行文件、检查文件路径权限等的其他线程,但这些建议都不起作用。我的代码是否有问题,或者我没有想到的其他问题


我使用的是Windows 10,我的帐户是本地管理员,我使用的是Python 3.8.1。非常感谢您的帮助。

您应该知道,在Windows中,有一些路径是您无法编写、添加。。。对于它,即使您拥有管理员权限。例如,您不能将任何文件添加到
C:\`、
C:\\Program Files
C:\\Program Files(x86)
、。。。因此,这里的解决方案是尝试通过另一个路径上传(首先将文件夹复制到另一个位置,如
C:\Users\user\Documents`Thank you@EthicalHackerMinh,我来试一试!