Hello,
I am having the below error when saving an event on the CRM module
ImportError: cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)
Kindly advise on this issue.
Hello,
I am having the below error when saving an event on the CRM module
ImportError: cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)
Kindly advise on this issue.
@Ayesha Please use this command and then check it
bench setup requirements --python
bench build
bench migrate
bench restart
Hi @Ayesha,
Use the command posted above, but can you send me the full stacktrace, because we want to check it out.
Below is the stacktrace:
Traceback with variables (most recent call last):
File “apps/frappe/frappe/app.py”, line 110, in application
response = frappe.api.handle(request)
request = <Request ‘https://erp.net/api/method/frappe.client.insert’ [POST]>
response = None
rollback = True
e = ImportError(“cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)”)
File “apps/frappe/frappe/api/init.py”, line 49, in handle
data = endpoint(**arguments)
request = <Request ‘https://erp.net/api/method/frappe.client.insert’ [POST]>
endpoint = <function handle_rpc_call at 0x7fccf7cc0940>
arguments = {‘method’: ‘frappe.client.insert’}
File “apps/frappe/frappe/api/v1.py”, line 36, in handle_rpc_call
return frappe.handler.handle()
method = ‘frappe.client.insert’
frappe = <module ‘frappe’ from ‘apps/frappe/frappe/init.py’>
File “apps/frappe/frappe/handler.py”, line 49, in handle
data = execute_cmd(cmd)
cmd = ‘frappe.client.insert’
data = None
File “apps/frappe/frappe/handler.py”, line 85, in execute_cmd
return frappe.call(method, **frappe.form_dict)
cmd = ‘frappe.client.insert’
from_async = False
server_script = None
method = <function insert at 0x7fccf7c8d120>
File “apps/frappe/frappe/init.py”, line 1768, in call
return fn(*args, **newargs)
fn = <function insert at 0x7fccf7c8d120>
args = ()
kwargs = {‘doc’: '{“doctype”:“Event”,“event_category”:“Envoi invitation LinkedIn”,“event_type”:“Private”,“starts_on”:“2024-09-17 16:25:50”,“undefined”:“CRM-LEAD-2024-01919”,“subject”:“CONSERVERIE”,“description”:“<div class=\“ql-editor read-mode\”>
<a href=\“Sales Navigator” rel=\“noopener noreferrer\” style=\“font-size: 16px; color: rgb(0, 115, 177);\”>
<span style=\“font-size: 16px; color: rgba(0, 0, 0, 0.6);\”>3rd degree connection· 3rd
<span style=\“color: rgba(0, 0, 0, 0.9);\”>Responsable achats / planification/ordonnancement / contrôle de gestion<span style=\“color: rgba(0, 0, 0, 0.9); background-color: rgb(255, 255, 255);\”> La belle
<a href=\“Sales Navigator” rel=\“noopener noreferrer\” style=\“font-size: 16px; color: rgb(0, 115, 177);\”>
<span style=\“font-size: 16px; color: rgba(0, 0, 0, 0.6);\”>3rd degree connection· 3rd
<span style=\“color: rgba(0, 0, 0, 0.9);\”>Responsable achats / planification/ordonnancement / contrôle de gestion<span style=\“color: rgba(0, 0, 0, 0.9); background-color: rgb(255, 255, 255);\”> La belle
<a href=\“Sales Navigator” rel=\“noopener noreferrer\” style=\“font-size: 16px; color: rgb(0, 115, 177);\”>
<span style=\“font-size: 16px; color: rgba(0, 0, 0, 0.6);\”>3rd degree connection· 3rd
<span style=\“color: rgba(0, 0, 0, 0.9);\”>Responsable achats / planification/ordonnancement / contrôle de gestion<span style=\“color: rgba(0, 0, 0, 0.9); background-color: rgb(255, 255, 255);\”> La belle
3rd degree connection· 3rd
Responsable achats / planification/ordonnancement / contrôle de gestion La belle
3rd degree connection· 3rd
Responsable achats / planification/ordonnancement / contrôle de gestion La belle
File “”, line 1006, in find_and_load_unlocked
name = ‘frappe.integrations.doctype.google_calendar.google_calendar’
import = <function _gcd_import at 0x7fccfa253400>
path = [‘apps/frappe/frappe/integrations/doctype/google_calendar’]
parent = ‘frappe.integrations.doctype.google_calendar’
parent_module = <module ‘frappe.integrations.doctype.google_calendar’ from ‘apps/frappe/frappe/integrations/doctype/google_calendar/init.py’>
spec = ModuleSpec(name=‘frappe.integrations.doctype.google_calendar.google_calendar’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>, origin=‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’)
File “”, line 688, in _load_unlocked
spec = ModuleSpec(name=‘frappe.integrations.doctype.google_calendar.google_calendar’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>, origin=‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’)
module = <module ‘frappe.integrations.doctype.google_calendar.google_calendar’ from ‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’>
File “”, line 883, in exec_module
self = <_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>
module = <module ‘frappe.integrations.doctype.google_calendar.google_calendar’ from ‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’>
code = <code object at 0x7fccf5374ea0, file “apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py”, line 1>
File “”, line 241, in _call_with_frames_removed
f =
args = (<code object at 0x7fccf5374ea0, file “apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py”, line 1>, {‘name’: ‘frappe.integrations.doctype.google_calendar.google_calendar’, ‘doc’: None, ‘package’: ‘frappe.integrations.doctype.google_calendar’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>, ‘spec’: ModuleSpec(name=‘frappe.integrations.doctype.google_calendar.google_calendar’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>, origin=‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’), ‘file’: ‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’, ‘cached’: ‘apps/frappe/frappe/integrations/doctype/google_calendar/pycache/google_calendar.cpython-310.pyc’, ‘builtins’: {‘name’: ‘builtins’, ‘doc’: "B…
kwds = {}
File “apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py”, line 12, in
from googleapiclient.discovery import build
name = ‘frappe.integrations.doctype.google_calendar.google_calendar’
doc = None
package = ‘frappe.integrations.doctype.google_calendar’
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>
spec = ModuleSpec(name=‘frappe.integrations.doctype.google_calendar.google_calendar’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f5120>, origin=‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’)
file = ‘apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py’
cached = ‘apps/frappe/frappe/integrations/doctype/google_calendar/pycache/google_calendar.cpython-310.pyc’
builtins = {‘name’: ‘builtins’, ‘doc’: “Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the nil' object; Ellipsis represents
…’ in slices.”, ‘package’: ‘’, ‘loader’: <class ‘_frozen_importlib.BuiltinImporter’>, ‘spec’: ModuleSpec(name=‘builtins’, loader=<class ‘_frozen_importlib.BuiltinImporter’>, origin=‘built-in’), ‘build_class’: , ‘import’: , ‘abs’: , ‘all’: , ‘any’: , ‘ascii’: , ‘bin’: , ‘breakpoint’: , ‘callable’: , ‘chr’: , ‘compile’: , ‘delattr’: , ‘dir’: , ‘divmod’: , ‘eval’: , ‘exec’: , ‘format’: , …
datetime = <class ‘datetime.datetime’>
timedelta = <class ‘datetime.timedelta’>
quote = <function quote at 0x7fccf9e80a60>
ZoneInfo = <class ‘zoneinfo.ZoneInfo’>
google = <module ‘google’ (<_frozen_importlib_external._NamespaceLoader object at 0x7fccfa120ee0>)>
requests = <module ‘requests’ from ‘env/lib/python3.10/site-packages/requests/init.py’>
parser = <module ‘dateutil.parser’ from ‘env/lib/python3.10/site-packages/dateutil/parser/init.py’>
File “env/lib/python3.10/site-packages/googleapiclient/discovery.py”, line 37, in
from email.generator import Generator as BytesGenerator
name = ‘googleapiclient.discovery’
doc = “Client for discovery based APIs.\n\nA client library for Google’s discovery based APIs.\n”
package = ‘googleapiclient’
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f7010>
spec = ModuleSpec(name=‘googleapiclient.discovery’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fccf40f7010>, origin=‘env/lib/python3.10/site-packages/googleapiclient/discovery.py’)
file = ‘env/lib/python3.10/site-packages/googleapiclient/discovery.py’
cached = ‘env/lib/python3.10/site-packages/googleapiclient/pycache/discovery.cpython-310.pyc’
builtins = {‘name’: ‘builtins’, ‘doc’: “Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the nil' object; Ellipsis represents
…’ in slices.”, ‘package’: ‘’, ‘loader’: <class ‘_frozen_importlib.BuiltinImporter’>, ‘spec’: ModuleSpec(name=‘builtins’, loader=<class ‘_frozen_importlib.BuiltinImporter’>, origin=‘built-in’), ‘build_class’: , ‘import’: , ‘abs’: , ‘all’: , ‘any’: , ‘ascii’: , ‘bin’: , ‘breakpoint’: , ‘callable’: , ‘chr’: , ‘compile’: , ‘delattr’: , ‘dir’: , ‘divmod’: , ‘eval’: , ‘exec’: , ‘format’: , …
absolute_import = _Feature((2, 5, 0, ‘alpha’, 1), (3, 0, 0, ‘alpha’, 0), 262144)
six = <module ‘six’ from ‘env/lib/python3.10/site-packages/six.py’>
zip = <class ‘zip’>
author = ‘jcgregorio@google.com (Joe Gregorio)’
all = [‘build’, ‘build_from_document’, ‘fix_method_name’, ‘key2param’]
BytesIO = <class ‘_io.BytesIO’>
http_client = <module ‘http.client’ from ‘/usr/lib/python3.10/http/client.py’>
urlencode = <function urlencode at 0x7fccf9e80dc0>
urlparse = <function urlparse at 0x7fccf9e5feb0>
urljoin = <function urljoin at 0x7fccf9e80670>
urlunparse = <function urlunparse at 0x7fccf9e80550>
parse_qsl = <function parse_qsl at 0x7fccf9e80940>
copy = <module ‘copy’ from ‘/usr/lib/python3.10/copy.py’>
OrderedDict = <class ‘collections.OrderedDict’>
File “/usr/lib/python3.10/email/generator.py”, line 17, in
from email.errors import HeaderWriteError
name = ‘email.generator’
doc = ‘Classes to generate plain text from a message object tree.’
package = ‘email’
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7fccf40bca30>
spec = ModuleSpec(name=‘email.generator’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fccf40bca30>, origin=‘/usr/lib/python3.10/email/generator.py’)
file = ‘/usr/lib/python3.10/email/generator.py’
cached = ‘/usr/lib/python3.10/email/pycache/generator.cpython-310.pyc’
builtins = {‘name’: ‘builtins’, ‘doc’: “Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the nil' object; Ellipsis represents
…’ in slices.”, ‘package’: ‘’, ‘loader’: <class ‘_frozen_importlib.BuiltinImporter’>, ‘spec’: ModuleSpec(name=‘builtins’, loader=<class ‘_frozen_importlib.BuiltinImporter’>, origin=‘built-in’), ‘build_class’: , ‘import’: , ‘abs’: , ‘all’: , ‘any’: , ‘ascii’: , ‘bin’: , ‘breakpoint’: , ‘callable’: , ‘chr’: , ‘compile’: , ‘delattr’: , ‘dir’: , ‘divmod’: , ‘eval’: , ‘exec’: , ‘format’: , …
all = [‘Generator’, ‘DecodedGenerator’, ‘BytesGenerator’]
re = <module ‘re’ from ‘/usr/lib/python3.10/re.py’>
sys = <module ‘sys’ (built-in)>
time = <module ‘time’ (built-in)>
random = <module ‘random’ from ‘/usr/lib/python3.10/random.py’>
deepcopy = <function deepcopy at 0x7fccf9ba44c0>
StringIO = <class ‘_io.StringIO’>
BytesIO = <class ‘_io.BytesIO’>
_has_surrogates = <function _has_surrogates at 0x7fccfa03ae60>
builtins.ImportError: cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)
The unattended-upgrades mechanism updated python3 earlier today on our servers, leading to incompatibilities between running python stdlib code and updated stdlib code. This is not a bug in Frappe.
Complete Error:
### App Versions
{
“erpnext”: “14.66.3”,
“frappe”: “14.71.0”,
“hrms”: “14.24.2”,
“india_compliance”: “14.26.1”,
“infrabeat_portal”: “0.0.1”,
“payments”: “0.0.1”
}
### Route
Workspaces/Recruitment
### Traceback
Traceback (most recent call last):
File “env/lib/python3.10/site-packages/googleapiclient/discovery.py”, line 35, in
from email.generator import BytesGenerator
File “/usr/lib/python3.10/email/generator.py”, line 17, in
from email.errors import HeaderWriteError
ImportError: cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 95, in application
response = frappe.api.handle()
File “apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/handler.py”, line 48, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/handler.py”, line 86, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “apps/frappe/frappe/init.py”, line 1611, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/init.py”, line 807, in wrapper_fn
retval = fn(*args, **get_newargs(fn, kwargs))
File “apps/frappe/frappe/desk/reportview.py”, line 29, in get
data = compress(execute(**args), args=args)
File “apps/frappe/frappe/desk/reportview.py”, line 75, in execute
return DatabaseQuery(doctype).execute(*args, **kwargs)
File “apps/frappe/frappe/model/db_query.py”, line 190, in execute
result = self.build_and_run()
File “apps/frappe/frappe/model/db_query.py”, line 205, in build_and_run
args = self.prepare_args()
File “apps/frappe/frappe/model/db_query.py”, line 245, in prepare_args
self.build_conditions()
File “apps/frappe/frappe/model/db_query.py”, line 590, in build_conditions
match_conditions = self.build_match_conditions()
File “apps/frappe/frappe/model/db_query.py”, line 947, in build_match_conditions
doctype_conditions = self.get_permission_query_conditions()
File “apps/frappe/frappe/model/db_query.py”, line 1029, in get_permission_query_conditions
c = frappe.call(frappe.get_attr(method), self.user)
File “apps/frappe/frappe/init.py”, line 1601, in get_attr
return getattr(get_module(modulename), methodname)
File “apps/frappe/frappe/init.py”, line 1335, in get_module
return importlib.import_module(modulename)
File “/usr/lib/python3.10/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1050, in _gcd_import
File “”, line 1027, in _find_and_load
File “”, line 1006, in _find_and_load_unlocked
File “”, line 688, in _load_unlocked
File “”, line 883, in exec_module
File “”, line 241, in _call_with_frames_removed
File “apps/infrabeat_portal/infrabeat_portal/infrabeat_portal/custom/interview/interview.py”, line 7, in
from frappe.integrations.doctype.google_calendar.google_calendar import delete_event_from_google_calendar
File “apps/frappe/frappe/integrations/doctype/google_calendar/google_calendar.py”, line 12, in
from googleapiclient.discovery import build
File “env/lib/python3.10/site-packages/googleapiclient/discovery.py”, line 37, in
from email.generator import Generator as BytesGenerator
File “/usr/lib/python3.10/email/generator.py”, line 17, in
from email.errors import HeaderWriteError
ImportError: cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)
### Request Data
{
“type”: “POST”,
“args”: {
“doctype”: “Interview”,
“fields”: “["name","job_applicant","status","docstatus","modified"]”,
“filters”: “{"scheduled_on":["Timespan","this month=","2"]}”,
“order_by”: “modified desc”,
“start”: 0,
“page_length”: 4
},
“headers”: {},
“error_handlers”: {},
“url”: “/api/method/frappe.desk.reportview.get”
}
### Response Data
{
“exception”: “ImportError: cannot import name ‘HeaderWriteError’ from ‘email.errors’ (/usr/lib/python3.10/email/errors.py)”
}
these commands work for me, thanks.
work for me. thank you. Seft hosted servers, and affected python versions are 3.10.x (v14 and v15 bench) and 3.9.x (v13 bench) but no issue on 3.11.x (v15 bench).
Thank you, Mr. Meet. This works for us!
Hello,
Just bench restart
is enough to get rid of this error.
However, it needs to be done as this error has the capacity to block every method once.
for a solution run the below
sudo pip install --upgrade urllib3
and also this
pip install --upgrade requests
this should fix it
Just bench restart
it solved.
bench clear-cache && bench restart
solved my problem.
I can open Email Queue, Email Account and Email Domain doctypes. And I’ve sent a test email to myself.
I don’t understand the real cause here. If a python package have some problems, it should not be fixed by just restarting the bench.
supervisorctl stop all
supervisorctl start all
Above command worked for me. Thanks.
Based on my tests prior to the restart it seems like this error appear only once per method and restarting allow to restart all methods at once, thus removing the error for all.
To be more precise about what I experienced :
On login : a method in error due to emails.errors
Refresh
HTML 500 error
Refresh
another method in error due to emails.errors
Refresh
yet another method in error due to emails.errors
Refresh
yet another one
So once a method has failed once it indeed didn’t fail anymore.
I suspect it is linked to Regression: ImportError for `HeaderWriteError` in long-running process post-Python update for CVE-2024-6923 · Issue #124170 · python/cpython · GitHub
In my case I just try 2 command which actually work.
bench update --patch
bench migration
NB: I am in Production mode .
I tried these commands, but it did not solve the issue.
without python upgrade how this issue is coming ?