IO Error storing data in brine

I have the following code in python to store data in pickle, but I get IO Error

[Errno 13] Permission denied: 'data.pkl' 

code

 def SaveUserData(request): datalist={} datalist['empid']='127113' datalist['empname']='eric' datalist['empphone']='66335500' datalist['email']=' eric.pk@moliba.com ' output = open('data.pkl', 'wb') pickle.dump(datalist, output) output.close() data = simplejson.dumps(datalist, indent=4) return HttpResponse(data,mimetype='application/javascript') 
+4
source share
3 answers

Well, I have set an absolute path and it will work!

 output = open('/home/user/test/wsservice/data.pkl', 'wb') 
+5
source

I noticed in Python 3.4, you can do it like:
output = open(str(dataList), "wb")

+1
source

In my case, it was a problem with my current directory.

I added the following lines to set the current working directory to my script directory.

We hope this solves the problem if administrator permission is not required to write to the script directory.

 import sys, os def getScriptPath(): return os.path.dirname(os.path.realpath(sys.argv[0])) print 'Current working directory : ', os.getcwd() os.chdir(getScriptPath()) print 'Changed working directory : ', os.getcwd() 
+1
source

Source: https://habr.com/ru/post/1343470/


All Articles