I have a socket server that is supposed to receive UTF-8 valid characters from clients.
The problem is some clients (mainly hackers) are sending all the wrong kind of data over it.
I can easily distinguish the genuine client, but I am logging to files all the data sent so I can analyze it later.
Sometimes I get characters like this ?
that cause the UnicodeDecodeError
error.
I need to be able to make the string UTF-8 with or without those characters.
Update:
For my particular case the socket service was an MTA and thus I only expect to receive ASCII commands such as:
EHLO example.com
MAIL FROM: <[email protected]>
...
I was logging all of this in JSON.
Then some folks out there without good intentions decided to send all kind of junk.
That is why for my specific case it is perfectly OK to strip the non ASCII characters.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…