Python文件写入error fmujie Python 2020-01-13 289 次浏览 1 次点赞 问题描述:测试requests库,抓了一张百度的logo,在文件写入的时候报了权限不够的错import requests response = requests.get('https://www.baidu.com/img/bd_logo1.png') print(response.content) with open('C:/baidu.png', 'wb') as f: f.write(response.content) f.close()PythonCopyTraceback (most recent call last): File "D:/PycharmProjects/untitled/test.py", line 42, in <module> with open('C:/baidu.png', 'wb') as f: PermissionError: [Errno 13] Permission denied: 'C:/baidu.png'PythonCopy解决方法:在当前项目下保存with open('baidu.png', 'wb') as f: f.write(response.content) f.close()PythonCopy在非系统盘下保存with open('D:/baidu.png', 'wb') as f: f.write(response.content) f.close()PythonCopyubuntu系统中给文件夹开放权限 本文由 fmujie 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。 点赞 1
还不快抢沙发