Skip to main content

Permission error

Traceback (most recent call last):
  File "/var/www/html/open-ai/summarise-ai.py", line 144, in <module>
    getfiles()
  File "/var/www/html/open-ai/summarise-ai.py", line 26, in getfiles
    summarise(filename)
  File "/var/www/html/open-ai/summarise-ai.py", line 105, in summarise
    savedata(filename, refine_outputs['output_text'])
  File "/var/www/html/open-ai/summarise-ai.py", line 118, in savedata
    with open(file_name, 'w') as json_file:
         ^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '2014-027.json'

 

The "PermissionError: [Errno 13] Permission denied" error in Ubuntu typically indicates that you don't have the necessary permissions to perform the operation you're attempting. This can happen when you're trying to perform an operation that requires superuser (root) privileges, or when you're trying to access or modify a file or directory without the appropriate permissions.

 

Here are some common scenarios that might trigger this error and how to address them:

 

Accessing Protected System Files

If you're trying to access or modify system files or directories that require root privileges, you should use the sudo command. For example, to edit a system configuration file, use

sudo nano /etc/somefile.conf

Modifying Files and Directories: If you're trying to modify a file or directory in your home directory or elsewhere, you may not have the necessary permissions. You can try changing the permissions using the chmod command or use sudo to escalate your privileges when needed.

Creating or Deleting Files and Directories: Ensure you have write permissions in the directory where you're trying to create or delete files. You can use chmod to change directory permissions, or use sudo when creating or deleting system-wide files or directories.

 

Using Virtual Environments

If you're working within a virtual environment for Python or other development environments, ensure that the virtual environment is activated when running your commands.

 

File Ownership

Check the ownership of files and directories. If a file is owned by a different user, you may not have permission to modify it. You can use chown to change ownership.
 

Here are some example commands for changing file permissions and ownership:

To change file permissions (e.g., give yourself write permissions)

chmod +w filename

To change directory permissions (e.g., give yourself write permissions)

chmod +w dirname

To change file ownership (e.g., change the owner to your username)

sudo chown yourusername filename

Remember to exercise caution when using sudo and be aware of the implications of modifying system files. Always back up important data before making changes to file permissions or ownership.

 

Related articles

Andrew Fletcher20 May 2024
Create a copy of files that go to the tmp directory
To review the content of files being generated in the /tmp directory on an Ubuntu server before Microsoft Defender removes them, you can use several approaches. &nbsp;Following is the approach we took.&nbsp;Real-Time MonitoringYou can set up a script to monitor the /tmp directory and log the...
Andrew Fletcher06 May 2024
Exploring historical memory usage monitoring with Sysstat
In the realm of system administration and monitoring, understanding memory usage trends is crucial for maintaining system health and performance. While tools like htop offer real-time insights into memory usage, they lack the capability to provide historical data. So, what if you need to analyze...