树莓派向Windows文件服务器复制图片遇ValueError报错求助
解决方法
- 修正源文件路径:你代码里的源路径是
/home/testuser/Pictures/Picture.png,但实际要复制的是/home/testuser/Desktop/Picture.png,路径不匹配会触发该报错(即便格式是绝对路径,但指向的文件或路径不存在时也会出现这个提示),先把源路径改成正确的绝对路径:path = "/home/testuser/Desktop/Picture.png" - 修正SMB目标路径格式:Windows文件服务器的路径在Python中需要正确转义,同时目标路径要对应你指定的
ImagesBackup共享和Test.png文件名,两种写法都可行:# 反斜杠写法(加r避免转义) pathpicture = r"\\Server\ImagesBackup\Test.png" # 正斜杠写法 pathpicture = "//Server/ImagesBackup/Test.png" - 完整修正后的代码:
import smbclient username = "你的Windows服务器用户名" password = "你的Windows服务器密码" src_path = "/home/testuser/Desktop/Picture.png" dst_path = r"\\Server\ImagesBackup\Test.png" smbclient.copyfile(src_path, dst_path, username=username, password=password) - 额外检查项:
- 确认树莓派上的
smbclient库为最新版本,可执行pip install --upgrade smbclient更新 - 确保Windows服务器的
ImagesBackup共享开启了读写权限,且所用用户名密码拥有该共享的写入权限 - 若存在DNS解析问题,可直接用服务器IP代替
Server(比如\\192.168.1.100\ImagesBackup\Test.png)
- 确认树莓派上的
内容的提问来源于stack exchange,提问作者PotterParsel
相关产品推荐
相关产品推荐

