python - 我的键盘记录器 Python 线程 Thread-25 中的异常
问题描述
我有这个远程键盘记录器,起初它可以正常发送电子邮件,但几分钟后它停止发送电子邮件,并抛出此错误:
Exception in thread Thread-25:
Traceback (most recent call last):
File "C:\Users\Lisandro0\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\Lisandro0\AppData\Local\Programs\Python\Python37\lib\threading.py", line 1177, in run
self.function(*self.args, **self.kwargs)
File "C:\Users\Lisandro0\Desktop\Desktop3\keylogger\crack.py", line 64, in report
self.sendmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
File "C:\Users\Lisandro0\Desktop\Desktop3\Keylogger\crack.py", line 53, in sendmail
server.sendmail(email, email, message)
File "C:\Users\Lisandro0\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 855, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xf1' in position 312: ordinal not in range(128)
我很感激阅读代码,因为它很短。
我很感激任何帮助
解决方案
错误信息很清楚:
...Python37\lib\smtplib.py...UnicodeEncodeError:“ascii”编解码器无法在位置 312 编码字符“\xf1”:序数不在范围内(128)
似乎 smtplib 对您的邮件内容进行编码有问题。
我做了一些源代码阅读。在 smtplib.py 中:
def sendmail(self, from_addr, to_addrs, msg, mail_options=(),
rcpt_options=()):
"""This command performs an entire mail transaction.
The arguments are:
- from_addr : The address sending this mail.
- to_addrs : A list of addresses to send this mail to. A bare
string will be treated as a list with 1 address.
- msg : The message to send.
- mail_options : List of ESMTP options (such as 8bitmime) for the
mail command.
- rcpt_options : List of ESMTP options (such as DSN commands) for
all the rcpt commands.
msg may be a string containing characters in the ASCII range, or a byte
string. A string is encoded to bytes using the ascii codec, and lone
\\r and \\n characters are converted to \\r\\n characters.
看这里:
msg 可以是包含 ASCII 范围内的字符的字符串,也可以是字节字符串
如果要发送非ascii内容的邮件,可以先将内容编码成字节串。
(顺便说一句,如果我猜对了,你的问题标题有点离题,没有抓住问题的关键。)
推荐阅读
- popup - 关于 Spotify 弹出窗口
- javascript - 如何在 Angular 中多次将相同的数据从父级传递到组件?
- ansible - 如何从模块结果中提取深度嵌套的值到变量中以供以后的任务使用?
- asp.net-core - 将 DeleteBehavior.Cascade 更改为 DeleteBehavior.Restrict 会导致 EF Core 删除外键
- google-apps-script - 带有枚举的 .gs 文件导致 Missing ;声明之前。(第 8 行,文件“代码”)
- asp.net-core - .net core mvc 模型属性类型 datetime 无法在 AJAX Post 请求中绑定
- c++ - 如何正确动画模型
- xamarin - Xamarin Forms MVVM 使用忙碌指示器验证表单
- git - 如何在 git 中对给定修订版中的所有文件进行 grep?
- json - 在angular7中读取复杂的嵌套json对象数组