Issue TypeError: object of type ‘EmailPolicy’ has no len() - cant send emails

Hi i have just updated to V12 from 11 and send emails i get a issue.
in the log it says
File “/usr/lib/python3.5/email/message.py”, line 49, in _formatparam
if value is not None and len(value) > 0:
TypeError: object of type ‘EmailPolicy’ has no len()

Same problem here

We are facing the same issue

Same here

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py”, line 329, in evaluate_alert
alert.send(doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py”, line 123, in send
self.send_an_email(doc, context)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py”, line 170, in send_an_email
and attachments[0].get(‘print_letterhead’)) or False))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 487, in sendmail
inline_images=inline_images, header=header, print_letterhead=print_letterhead)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 162, in send
print_letterhead=print_letterhead)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 183, in add
email_queue = get_email_queue(recipients, sender, subject, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 218, in get_email_queue
header=kwargs.get(‘header’))
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 33, in get_email
emailobj = EMail(sender, recipients, subject, reply_to=reply_to, cc=cc, bcc=bcc, email_account=email_account, expose_recipients=expose_recipients)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 75, in init
self.msg_root = MIMEMultipart(‘mixed’, policy=policy.SMTPUTF8)
File “/usr/lib/python3.5/email/mime/multipart.py”, line 36, in init
MIMEBase.init(self, ‘multipart’, _subtype, **_params)
File “/usr/lib/python3.5/email/mime/base.py”, line 25, in init
self.add_header(‘Content-Type’, ctype, **_params)
File “/usr/lib/python3.5/email/message.py”, line 541, in add_header
parts.append(formatparam(k.replace('', ‘-’), v))
File “/usr/lib/python3.5/email/message.py”, line 49, in _formatparam
if value is not None and len(value) > 0:
TypeError: object of type ‘EmailPolicy’ has no len()

Solved.

Go to /home/frappe/frappe-bench/apps/frappe/frappe/email Folder

Replace the content of email_body.py with content from:

Run bench restart

And Done.

2 Likes

Hi, thank you but now it says
_recipients=expose_recipients)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 71, in init
if PY3:
NameError: name ‘PY3’ is not defined

I’m facing this after minor updating v11 and then upgrading to v12. I also updated the email password since I could not get the previously saved password to work (encryption key not found, maybe this was my mistake) so I updated the password for the email account and can successfully save.

thank you very much - this works for me!

1 Like

Thanks - this sorted it out for us too. Nothing hitting our email queue at all.
Completed minor update from 12.7.x up to 12.8.4 which started this.

Hey, this solution is not working for me

Traceback (most recent call last):
File “/usr/local/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/home/frappe/.bench/bench/cli.py”, line 41, in cli
bench_command()
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/frappe/.bench/bench/commands/utils.py”, line 26, in restart
restart_supervisor_processes(bench_path=‘.’, web_workers=web)
File “/home/frappe/.bench/bench/utils.py”, line 519, in restart_supervisor_processes
supervisor_status = subprocess.check_output([‘sudo’, ‘supervisorctl’, ‘status’], cwd=bench_path)
File “/usr/lib/python3.5/subprocess.py”, line 316, in check_output
**kwargs).stdout
File “/usr/lib/python3.5/subprocess.py”, line 398, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ‘[‘sudo’, ‘supervisorctl’, ‘status’]’ returned non-zero exit status 1

it gives message User None not found

I got around this by upgrading python version to 3.7 and migrating the environment accordingly:

  1. Upgrade to python 3.7
  2. bench migrate-env python3.7

Cheers

@wale
can you also mention what does migrating to python@3.7 actually do?

@Narahari_Dasa

can you mention why does it start working after replacing v13’s email body?

@nabinhait
can this release be made for v12?
facing this error on frappe version 12.14.0

As I already mentioned on Github, I believe there were some bugs / compatibility issues with 3.6 so 3.7 was more generally recommended

Cheers

It is because of Python Version issue. This problem solution is for v3.6. For v3.7, this is not even a problem.