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 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...
Andrew Fletcher01 May 2024
Common commands used in Ubuntu - in progress
A growing list of commands I've used and what they do in no specific ordersudo snap install bw ps aux | grep java whoami ip addr show uptime sudo apt update &amp;&amp; sudo apt upgrade -y cat /etc/os-release sudo apt-get install needrestart sudo reboot sudo needrestart sudo ckan sysadmin...