i have a following code in a python to store data in pickle , but i am getting IO Error
[Errno 13] Permission denied: 'data.pkl'
Code
def SaveUserData(request):
datalist={}
datalist['empid']='127113'
datalist['empname']='eric'
datalist['empphone']='66335500'
datalist['email']='[email protected]'
output = open('data.pkl', 'wb')
pickle.dump(datalist, output)
output.close()
data = simplejson.dumps(datalist, indent=4)
return HttpResponse(data,mimetype='application/javascript')
To save a pickle, use pickle. dump . A convention is to name pickle files *. pickle , but you can name it whatever you want.
The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. To fix this error, use the chmod or chown command to change the permissions of the file so that the right user and/or group can access the file.
dump() function to store the object data to the file. pickle. dump() function takes 3 arguments. The first argument is the object that you want to store. The second argument is the file object you get by opening the desired file in write-binary (wb) mode.
Pickle dump replaces current file data.
Well i assigned the absolute path & it worked !!
output = open('/home/user/test/wsservice/data.pkl', 'wb')
I've noticed in Python 3.4 you can do it like: output = open(str(dataList), "wb")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With