Permission denied after using PyInstaller to create Python executable -



Permission denied after using PyInstaller to create Python executable -

i've created little web server using bottle framework serve 1 webpage. done python script "hello.py". webpage generated "hello.py", i'm able edit contents of file called "data.txt". works fine when run "hello.py" terminal (python hello.py).

but when create executable using pyinstaller run problem. i'm unable write "data.txt" file. error message "permission denied". else in executable works except this!

prior creating executable, set "data.txt" permissions 777. didn't help. tried potential solution found here - no luck. looked this:

def resource_path(relative_path): """ absolute path resource, works dev , pyinstaller """ try: # pyinstaller creates temp folder , stores path in _meipass base_path = sys._meipass except exception: base_path = os.path.abspath(".") homecoming os.path.join(base_path, relative_path) def fix_ownership(path): """change owner of file sudo_uid""" uid = os.environ.get('sudo_uid') gid = os.environ.get('sudo_gid') if uid not none: os.chown(resource_path(path), int(uid), int(gid)) @post('/data<datavalue>') # or @route('/login') def data(datavalue): thepostrequest = str(request.query_string) newpostrequest = string.replace(thepostrequest, '%22', '\"') fix_ownership("data.txt") open("data.txt","w") fo: fo.write('data = '+newpostrequest) homecoming

i had high hopes, didn't work either. here's code stands (i'm new python allow me know of glaring mistakes):

from bottle import route, run, static_file, get, post, request, response, redirect import os import string import sys def resource_path(relative_path): """ absolute path resource, works dev , pyinstaller """ try: # pyinstaller creates temp folder , stores path in _meipass base_path = sys._meipass except exception: base_path = os.path.abspath(".") homecoming os.path.join(base_path, relative_path) @get('/count<devicenumber>') # or @route('/login') def count(devicenumber): homecoming def fix_ownership(path): """change owner of file sudo_uid""" uid = os.environ.get('sudo_uid') gid = os.environ.get('sudo_gid') if uid not none: os.chown(resource_path(path), int(uid), int(gid)) @post('/data<datavalue>') # or @route('/login') def data(datavalue): thepostrequest = str(request.query_string) newpostrequest = string.replace(thepostrequest, '%22', '\"') newpostrequest = newpostrequest.replace('%27', '\'') # not work after executable created pyinstaller - permission denied :( open("data.txt","w") fo: fo.write('data = '+newpostrequest) homecoming @get('/ajax<nocache>') # or @route('/login') def ajax(nocache): homecoming @get('/<filename:re:.*\.(jpg|png|gif|ico)>') def send_image(filename): print "getting image..." homecoming static_file(filename, root=resource_path('./')) @get('/<filename:path>') def send_static(filename): homecoming static_file(filename, root=resource_path('./')) # homecoming static_file(filename, root=os.path.join(sys._meipass, './')) @route('/formsubmit', method='post') def formsubmit(): redirect("/hello", 303) homecoming @route('/hello') @route('/hello', method='get') def hello(): homecoming ''' <!doctype html> <html> <head> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"> --> <script type="text/javascript" src="data.txt"></script> <script type="text/javascript" src="myjavascript.js"></script> <link rel="stylesheet" type="text/css" href="style.css"></script> <title>canari jr. | home</title> </head> <body onload="preparepage()"> <div id="spinner"></div> <div id="container"> <div id="headerdiv"> <div id="logodiv"><a href="/" onclick="showhome(); homecoming false;"> <img src="clogo.png" alt="canari jr. logo"> </a> </div> <div id="navdiv"> <a href="/" onclick="showhome(); homecoming false;"><p id="homebtn" style="color:black;background-color:white">home</p></a> <a href="/" onclick="showsetup(); homecoming false;"><p id="settingsbtn">settings</p></a> </div> </div> <div id="contentdiv"> </div> <div id="adddiv" style="text-align:center;display:none;"> <h2>add new device</h2> <form method="post" id="deviceform" action="/formsubmit" onsubmit="writetxt('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p');"> <p style="background-color:#f5f5f5;" id="devicedropdown">monitor type:<select name="" id="devicelist" onchange="loadcontenta(this.value)"> <option value="default">choose one...</option> <option value="temp">temperature</option> <option value="humidity">humidity</option> <option value="analog">analog</option> <option value="digital">digital</option> <option value="counter">counter</option> </select></p> <div id="cleardiv" style="clear:both"></div> <a href="/" id="cancelbtn" onclick="hideadddiv(); homecoming false;">cancel</a> </form> </div> <div id="editdiv" style="display:none"> </div> <div id="setupdiv" style="display:none"> <h2 style="margin-bottom:35px; border:3px solid #8c8c8c; width:40%; margin:0 auto; padding:10px">change ip address</h2> <form method="post" onsubmit="submitip('ipaddress'); homecoming false;"> <p>new ip address: <input type="text" name="ipaddress" id="ipaddress"><input type="submit" value="submit" style="padding:5px 10px 5px 10px"> </p> <p>make sure <span style="color:red">write downwards ip address</span> need finish setup.</p><br> </form> <h2 style="margin-bottom:35px; border:3px solid #8c8c8c; width:40%; margin:0 auto; padding:10px;margin-top:45px;">binding mode</h2> <p>binding mode currently:</p> <a href="/" id="bindbtn" onclick="bindon(); homecoming false;" class="btn">off</a> <p>(click change)</p> </div> </div> </body> </html> ''' run(host='0.0.0.0', port=8080, debug=true)

i'm using mac osx.

i figured out! first, had refer "data.txt" file using function:

def resource_path(relative_path): """ absolute path resource, works dev , pyinstaller """ try: # pyinstaller creates temp folder , stores path in _meipass base_path = sys._meipass except exception: base_path = os.path.abspath(".") homecoming os.path.join(base_path, relative_path)

i used so:

thedatafile = resource_path('./data.txt')

then when went write file, worked! this:

def data(datavalue): thepostrequest = str(request.query_string) newpostrequest = string.replace(thepostrequest, '%22', '\"') newpostrequest = newpostrequest.replace('%27', '\'') newpostrequest = newpostrequest.replace('%20', ' ') newpostrequest = newpostrequest.replace('%7b', '{') newpostrequest = newpostrequest.replace('%7d', '}') print "this info value: " + newpostrequest thedatafile = resource_path('./data.txt') open(thedatafile,"w") fo: fo.write('data = '+newpostrequest) homecoming

python python-2.7 bottle pyinstaller

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -