I am trying to send myself PDF files per E-mail with Python. I am able to send myself the binary code of a PDF file, but I am not able to reconstruct the PDF file from this binary code.
Here is how I obtain the binary code of a PDF file:
file = open('code.txt', 'w')
for line in open('somefile.pdf', 'rb').readlines():
file.write(str(line))
file.close()
Here is how I try to create a PDF file from the binary code:
file = open('new.pdf', 'wb')
for line in open('code.txt', 'r').readlines():
file.write(bytes(line))
file.close()
I then recieve this error:
Traceback (most recent call last): File "something.py", line 3, in file.write(bytes(line)) TypeError: string argument without an encoding
What did I do wrong?