# File permissions denied in python version

**URL:** <https://rpi-rgb-led-matrix.discourse.group/t/file-permissions-denied-in-python-version/258>\
**Category:** Uncategorized\
**Created:** [June 19, 2021, 6:54pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/file-permissions-denied-in-python-version/258 "2021-06-19T18:54:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![clumpo](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clumpo](https://rpi-rgb-led-matrix.discourse.group/u/clumpo)\
**Post date:** [June 19, 2021, 6:54pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/file-permissions-denied-in-python-version/258/1 "2021-06-19T18:54:45Z")

</div>

Ive made a simple image viewer using the python examples and it all works fine. However, I would also like to save the image file used to a text file.

Code is:

```auto
#!/usr/bin/env python
import time
import sys

from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image

def write_to_file(filename, towrite):
    f = open(filename, "w")
    print(towrite)
    f.write(towrite)
    f.close()

if len(sys.argv) < 2:
    sys.exit("Require an image argument")
else:
    image_file = sys.argv[1]

image = Image.open(image_file)

# Configuration for the matrix
options = RGBMatrixOptions()
options.rows = 32
options.chain_length = 4
options.parallel = 1
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'

matrix = RGBMatrix(options = options)
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
matrix.SetImage(image.convert('RGB'))

write_to_file("marquee.txt", image_file)

try:
    print("Press CTRL-C to stop.")
    while True:
        time.sleep(100)
except KeyboardInterrupt:
    sys.exit(0)

```

However, when I run this, I get a permission error:

File “file\_test3.py”, line 34, in   
write\_to\_file(“marquee.txt”, image\_file)  
File “file\_test3.py”, line 9, in write\_to\_file  
f = open(filename, “w”)  
PermissionError: [Errno 13] Permission denied: ‘marquee.txt’

I tried various combinations of the code and there seems to be an interaction when definining the ‘matrix’. If I comment out the lines:

```auto
matrix = RGBMatrix(options = options)
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
matrix.SetImage(image.convert('RGB'))

```

Then I no longer get the permissions error. Any ideas?

---

<div class="post-metadata">

**Author:** ![marcmerlin](https://yyz2.discourse-cdn.com/free1/user_avatar/rpi-rgb-led-matrix.discourse.group/marcmerlin/32/40_2.png) [@marcmerlin](https://rpi-rgb-led-matrix.discourse.group/u/marcmerlin)\
**Post date:** [June 21, 2021, 6:25pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/file-permissions-denied-in-python-version/258/2 "2021-06-21T18:25:50Z")

</div>

yes, the library changes uid to daemon, so you’re not root anymore.  
Try making your parent directory chmod 1777 and things will work.
