I tried file encryption method using Crypto Library. But have a problem with receiving side try to decode file size. This is my code
Sender Code
client.send('file.txt'.encode())
client.send(str(file_size).encode())
client.sendall(encrypted)
client.send(b'<END>')
client.close()
Receiver Code
file_name = client.recv(1024).decode()
print(file_name)
file_size = client.recv(1024).decode()
print(file_size)
I tried file_size = client.recv(1024).decode('utf8', errors='replace') but this not worked
This is the error,
file.txt
Traceback (most recent call last):
File "d:\Python\FileShare\reciver.py", line 18, in <module>
file_size = client.recv(1024).decode('utf8')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 2: invalid start byte
I found a solution this problem. Change a while loop to the process.
this is the code I change,
client and server both side make these changes and it is work properly!