You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派向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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 12:43:27