Bonjour tout le monde, alors j'apprend python(3)

Mais j'ai un problème, je cherche à faire un programme qui traduise un texte normal, en binaire, puis qu'il l'écrive dans un fichier. hors, quand j'essaye je me retrouve face à ca :

TypeError: 'str' does not support the buffer interface

voici mon code.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
import os
 
print("Programme permettant de traduire une str en b.\n")
f=open('text2.txt','w')
 
while 1:
    mot=input("Dire: ")
    f.write(mot)
    if mot=='':
        break
        f.close()
 
f=open('text2.txt','rb')
octets=f.read()
f.close()
 
f=open('text2.txt','wb')
for oct in octets:
    f.write("{}".format(str(oct)))
    f.close()
alors j'ai essayer à l'avant derniere ligne sans le "str(oct)" ...
ca m'affiche :

TypeError: 'int' does not support the buffer interface