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 Fletcher16 Jul 2024
How to efficiently use find and replace in VS Code
When it comes to text editing, Visual Studio Code (VS Code) is one of the most popular tools among developers. One of its powerful features is the Find and Replace function, which can save you countless hours of manual editing. In this article, we'll explore how to use this function to replace all...
Andrew Fletcher09 Jun 2024
Overcoming startup challenges with Apache Solr on Ubuntu 24.04
Recently, after upgrading to Ubuntu 24.04, we encountered a significant challenge with our Apache Solr service—it refused to restart. This post documents the steps I took to diagnose and resolve the issues, providing a clear guide for anyone facing similar troubles.&nbsp;Initial troubleshootingThe...