0

I am really new in Python. I have made a python program for merging pdfs. The problem is when the program want to save the completed merged pdf on the server (at work), it doesn't work. I get an Error: Permission denied. But when I say to my program that the merged pdf file must be saved on a local folder (on my pc), it works perfectly. How can I fix this?

An example of pathpdflocation_compleet (local on my pc) :

C:\Users\myname\Documents\TF\Compleet\pdfcompleet.pdf

An example of pathpdflocation_compleet (at work) :

W:\xxx\xxx\xxx\xx\pdfcompleet.pdf

Can I give my python script permission for saving this pdf file on the server?

I have searched on the web, but I don't find anything about this. I have already tried with double backslashes and / or \. I have already tried to give the full name of the server.


 '''
 python
 '''

 from PyPDF2 import PdfFileMerger
 from openpyxl import load_workbook
 filepath=input ('Path of the Merge Excel: ')
 wb=load_workbook(filepath,data_only = True)

 fiche1="A1"
 file1=sheet[fiche1].value
 fiche2="A2"
 file2=sheet[fiche2].value 

 pdf2merge = [file1,file2,...]

 merger = PdfFileMerger()

 for pdf in pdf2merge:
     merger.append(pdf)

 with open(pathpdflocation_compleet, 'wb') as fout:
     merger.write(fout)

The error is this:

IOError: [Errno 13] Permission denied


I want the file to be saved on the server.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Is it on a network mounted drive? Did you try the local disk C:\ for example? – Vikramaditya Gaonkar Aug 02 '19 at 12:49
  • My program works perfect with my local disk C:\. The complete name of the server is \\xxx.veibe.net\KV_Data\ , but I already tried that, and it gives the same error. – Lennart VH Aug 02 '19 at 12:56
  • It is likely that the server permissions need to be adjusted to allow anything (including your python program) from your machine 'write' access to that folder on the server. – Kevin Aug 02 '19 at 12:58
  • I have full permission to the server. So I can manually save a pdf file to the server map. Is it correct that I must give the python program permission? How can I do that? I have made an executable file of my python script. – Lennart VH Aug 02 '19 at 13:07
  • This looks very similar to this [question](https://stackoverflow.com/questions/18529323/permission-denied-error-while-writing-to-a-file-in-python). Did you try all of the suggestions there? – Kevin Aug 02 '19 at 13:07
  • Can you post your full code? This may rule out the possibility of something having a lock/handle on the file at the time you're attempting to write to it. – alex Aug 02 '19 at 13:10
  • @squareskittles I have read that question, and I gave the full path every time.@alex My code is really long. I have made a recap. – Lennart VH Aug 02 '19 at 13:23
  • You might also have to netstat the network drive before you send the document there. https://www.howtogeek.com/118452/how-to-map-network-drives-from-the-command-prompt-in-windows/ – Vikramaditya Gaonkar Aug 02 '19 at 14:59

0 Answers0