permission denied for creating pdf files

I want to create a pdf file using fpdf module. It worked before but recently it does work and gives the following error

import fpdf
pdf_tw = fpdf.FPDF(format='letter')
pdf_tw.set_font("Arial", 'B', size=18)
pdf_tw.write(5,'2000 first tweets that have been detected as relevant for business:')


PermissionError Traceback (most recent call last)
9 pdf_tw.ln()
—> 10 pdf_tw.output(name=“tweets.pdf”)

~\Anaconda3\lib\site-packages\fpdf\ in output(self, name, dest)
1077 elif dest==‘F’:
1078 #Save to local file
→ 1079 f=open(name,‘wb’)
1080 if(not f):
1081 self.error('Unable to create output file: '+name)

PermissionError: [Errno 13] Permission denied: ‘tweets.pdf’

Thanks for the help.

Do you run this code locally on your computer or laptop? Or on a JupyterHub? Either way it seems like a permission problem, as the error message shows. You might want to try to save the PDF with an absolute path. If it was really just the update of the fpdf library, better check whether there were any changes with fpdf. Currently, I don’t see any issue with Jupyter Notebook here.

1 Like

I run it on my laptop. Even if I give the full path the problem remains. I had written the files before with this code exactly on the same directory many times but suddenly this problem started. It is not a problem form pdpf since it occurs the other codes. Please see below. I understood that this problem happens just for the pdf and docx extensions. If I use txt extension this problem does not happen I run the program as the administrator.

from pathlib import Path
p = Path('.') ## if you want to write to current directory
with open(p / 'testsss.pdf', 'w') as f:
    f.write('test message')

PermissionError Traceback (most recent call last)
1 from pathlib import Path
2 p = Path(’.’) ## if you want to write to current directory
----> 3 with open(p / ‘testsss.pdf’, ‘w’) as f:
4 f.write(‘test message’)

PermissionError: [Errno 13] Permission denied: 'testsss.pdf

Then the error is on the level of the operating system. Maybe you can find some advice on stackoverflow for how to set file and folder permissions?

I had seen all of those solutions at stackoverflow before I sent my question. No one worked.