I am using Django to display my code in an html format using class based views. My code reads a log file and displays stats based on what is in there. When I try to access the log file from my computer this error message is displayed:
[Errno 13] Permission denied: 'C:/Users/bhattaar/Downloads/access.log'
I first tried going through the properties of the folder to make sure everything was set to read only (which it already was) and then I tried running the command prompt as an administrator and it still would not work.
The line the error appears on is this:
log = open('C:/Users/bhattaar/Downloads/access.log', 'r')
Does anyone know how I can resolve this issue?
Does this work?
Taken from here
log_file = r'C:/Users/bhattaar/Downloads/access.log'
with open(log_file) as f:
f = f.readlines()
Related
I am trying to run this code locally:
https://gist.github.com/shashank524/74d8f46d5de633b84e2265fcc34774de#file-tabledetection-ipynb
After installing required packages, when I am trying to run this line:
import layoutparser as lp
# PubLayNet
model = layoutparser.Detectron2LayoutModel('lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config',extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.81],label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"})
I receive this error:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\username/.torch/iopath_cache\\s/f3b12qc4hc0yh4m\\config.yml?dl=1.lock'
I looked into the directory and there was no config file available.
I tried to download the config file from here (https://layout-parser.readthedocs.io/en/latest/notes/modelzoo.html) and put it in the directory but it didn't solve the issue!
Even I got a similar error. I tried out manually some work around in Windows.
I am using your case as example: OSError: [Errno 22] Invalid argument: 'C:\Users\username/.torch/iopath_cache\s/f3b12qc4hc0yh4m\config.yml?dl=1.lock'
Please follow the following process.
Navigate to C:\Users\username/.torch/iopath_cache\s/f3b12qc4hc0yh4m\config.yml
Open that config.yaml file
Scroll down to WEIGHTS: https://www.dropbox.com/s/h7th27jfv19rxiy/model_final.pth?dl=1 should be around 265 line.
Copy that link and paste it in your browser, a 'model_final.pth' will be downloaded. Copy this file to your desired folder.
Now replace the path to WEIGHTS: your_desired_folder\model_final.pth
Save it and run the code it works!
But there is a small work around I think before you do this (if you have not done)
iopath work around
https://github.com/Layout-Parser/layout-parser/issues/15 (Github link to the issue)
Hope this helps!
I am deploying a web server, and after I finish compiling.There are the executing documents;
01client.c client epoll_server.c server
Then I try to run server
./server
There is an error which I cant fix it. I have search ways for solving but still can't fix it.
load error: No such file or directory
Maybe some one can help me,please!
Thanks a lot!!!!
System utilities print the program generating the error at the beginning of the line followed by other useful information such as the name of the missing file, so this is probably an error from a user program. I can duplicate the error as follows:
errno = 2;
perror("load error");
which prints:
load error: No such file or directory
Look for the perror line in the server code. If it isn't clear what file it can't find, print the string from the failed command it is reporting.
I tried to make it so that my bot will create a directory inside a directory in the bot to store server data.
I originally just wanted to create the directory without worrying about permissions:
#client.event
async def on_guild_join(guild):
print(f'Recognized that Beatboxer has joined {guild.name}')
guild_path = rf'/guilds/{guild.id}'
if not os.path.exists(guild_path):
os.makedirs(rf'/guilds/{guild.id}')
An error message came up that looked like this:
Ignoring exception in on_guild_join
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "main.py", line 227, in on_guild_join
os.makedirs(rf'guilds/{guild.id}')
File "/usr/lib/python3.8/os.py", line 223, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 'guilds/727168023101964298'
I then tried adding os.chmod into the code, but, for some reason, still had the same error message.
os.chmod("guilds", 777)
#client.event
async def on_guild_join(guild):
print(f'Recognized that Beatboxer has joined {guild.name}')
guild_path = rf'/guilds/{guild.id}'
if not os.path.exists(guild_path):
os.makedirs(rf'/guilds/{guild.id}')
Also, calling os.chdir and changing the directory into there did not work, and had a similar error message.
os.chmod("guilds", 777)
#client.event
async def on_guild_join(guild):
print(f'Recognized that Beatboxer has joined {guild.name}')
guild_path = rf'/guilds/{guild.id}'
if not os.path.exists(guild_path):
os.chdir('/guilds')
os.makedirs(rf'{guild.id}')
Finally, I attempted one last thing (which obviously still didn't work), which was os.popen, which opens a pipe for a command, allowing it to transfer the output to a file which is editable by other programs (which therefore should not regard what any permissions do):
#client.event
async def on_guild_join(guild):
print(f'Recognized that Beatboxer has joined {guild.name}')
guild_path = rf'/guilds/{guild.id}'
if not os.path.exists(guild_path):
os.popen(os.makedirs(rf'/guilds/{guild.id}'))
All of these attempted codes have very similar error messages, particularly Errno 13. Computer configuration will most likely not work. Please help? Thank you!
The problem is not that the functions you use are wrong.
You are actually giving a directory location you dont have permission to.
There are 2 kinds of paths to folders. Absolute paths and relative paths. In the examples you gave you used absolute path. When you use the absolute path you use the root directory as starting point. The thing with online IDE's is that you often dont have direct access to the root directory. Thus making new directories will give permission errors.
So how do we fix this? I suggest using relative paths instead. To fix this in your code is really easy, instead of doing this:
'/path/to/folder'
Do this:
'./path/to/folder'
By using ./ instead of /. You use the current folder as your starting point instead of the root directory. As you often have access to the current folder this wont give permission errors.
OS: Windows 10
Python: 3.6 (Anaconda)
I am trying to use a simple temporary file with a context manager to write a simple csv.
import csv
import tempfile
fp = tempfile.TemporaryFile()
with open(fp.name,'w',newline='') as f:
csv_out = csv.writer(f)
csv_out.writerow(['first_name','last_name'])
csv_out.writerow(['foo','bar'])
Running this results in this permission error:
with open(fp.name,'w',newline='') as f:
E PermissionError: [Errno 13] Permission denied: 'C:\\TEMP\\tmp2bqke7f6'
Changing the Windows permission status on the temp directory C:\TEMP\ to allow full access by all users does not help.
Per this post I tried running my Windows cmd as Admin, still did not work.
Searching for a similar problem (link), I found (and tested) a solution which works for your problem as well.
You just need to add a delete=False argument in your fp = tempfile.TemporaryFile() line.
It seems that the file actually gets created in that line, and then trying to open it and write in it a second time (with open(fp.name)...) forbids you do to so.
I have a Python app using Pygraphviz that works fine locally, but on the server the draw function throws an error. It happens in make_svg. The following lines are the relevant part of the errors I get. (The full trail is here.)
File "/path/to/app/utils/make_svg.py", line 17, in make_svg
prog='dot'
File "/path/to/pygraphviz/agraph.py", line 1477, in draw
fh = self._get_fh(path, 'w+b')
File "/path/to/pygraphviz/agraph.py", line 1506, in _get_fh
fh = open(path, mode=mode)
FileNotFoundError: [Errno 2] No such file or directory: 'app/svg_files/nope.svg'
Logging type(g) gives <class 'pygraphviz.agraph.AGraph'> as expected.
I work in a virtualenv in a mod_wsgi 4.6.5/Python3.7 environment on a Webfaction server.
Locally I use a virtualenv with Python 3.5.
The version of Pygraphviz is 1.3.1.(First I had 1.5 on the server. The error was exactly the same, except for the line numbers.)
What can I do?
The same error is described in this bug report from last year.
I don't get which directory I am supposed to create. svg_files exists and has rights 777.
The draw function at the end of make_svg should create the SVG.(And at the end of extract_coordinates_from_svg the file is removed again.)The file name is a hash created in connected_dag (svg_name).
On the server app/svg_files seems not to describe the same place as locally.
I defined the path unambiguously, and now it works.
file_path = '{grandparent}/svg_files/{name}.svg'.format(
grandparent=os.path.dirname(os.path.dirname(__file__)),
name=name
)
g.draw(file_path, prog='dot')