Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeError while handling a bug #757

Open
criptocoko opened this issue Mar 1, 2023 · 6 comments · May be fixed by #762
Open

UnicodeError while handling a bug #757

criptocoko opened this issue Mar 1, 2023 · 6 comments · May be fixed by #762

Comments

@criptocoko
Copy link

I'm getting the following error while sending an email when a bug occurs:
ERROR HAPPENS ...
...
..
During handling of the above exception, another exception occurred:

File "/usr/local/lib/python3.10/dist-packages/web/application.py", line 278, in process
return p(lambda: process(processors))
File "/usr/local/lib/python3.10/dist-packages/web/application.py", line 686, in processor
return handler()
File "/usr/local/lib/python3.10/dist-packages/web/application.py", line 278, in
return p(lambda: process(processors))
File "/usr/local/lib/python3.10/dist-packages/web/application.py", line 287, in process
raise self.internalerror()
File "/usr/local/lib/python3.10/dist-packages/web/debugerror.py", line 354, in emailerrors_internal
sendmail(
File "/usr/local/lib/python3.10/dist-packages/web/utils.py", line 1449, in sendmail
mail.send()
File "/usr/local/lib/python3.10/dist-packages/web/utils.py", line 1544, in send
self.send_with_smtp(message_text)
File "/usr/local/lib/python3.10/dist-packages/web/utils.py", line 1592, in send_with_smtp
smtpserver.sendmail(self.from_address, self.recipients, message_text)
File "/usr/lib/python3.10/smtplib.py", line 875, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 12430: ordinal not in range(128)

If i add message_text.enconde('ascii", errors="ignore") the problem is fixed but i don't want to patch webpy code.... is there a way to fix this?

@iredmail
Copy link
Contributor

iredmail commented Mar 2, 2023

Please show us code snippet to reproduce this issue.

@criptocoko
Copy link
Author

criptocoko commented Mar 2, 2023

Sure, here is an example of web.debugerror.emailerrors_internal() that generates a non unicode char

import web

web.config.smtp_server="postfix" # valid smtp
web.config.smtp_port=587 

web.utils.sendmail( "your buggy site <root@example.com>", 
"the bugfixer <bugfixer@example.com>", 
"bug:bla bla", "message", 
attachments=[dict(filename="bug.html", content=web.utils.safestr('  bla ’ bla '))]) ## example of attachemnt with a non unicode char  '\u2019' 

@criptocoko
Copy link
Author

by the way.. because of this error i had to reboot my servers.. Since everytime it tried to send an email it crashed because of the bug, that generates another email to send, so it generated a loop of never sending emails ..

Z4nzu added a commit to Z4nzu/webpy that referenced this issue Mar 4, 2023
@Z4nzu Z4nzu linked a pull request Mar 4, 2023 that will close this issue
Z4nzu added a commit to Z4nzu/webpy that referenced this issue Mar 4, 2023
@cclauss
Copy link
Contributor

cclauss commented Mar 4, 2023

@Z4nzu It would be helpful if we created a https://github.com/webpy/webpy/tree/master/tests/test_debugerror.py file that contained at least one pytest that failed based on @criptocoko scenarios above but then passed when #762 is merged. That way we would have a test in place to ensure that we never have this problem again. Thoughts?

@Z4nzu
Copy link

Z4nzu commented Mar 4, 2023

Could you please explain a bit more in detail ?

I got your point.! Are you talking about creating a test case file for the issue we resolved ?

@cclauss
Copy link
Contributor

cclauss commented Mar 4, 2023

Correct. Please look at the other files in tests/ to see that they contain pytests that we run in our GitHub Actions.

@webpy webpy deleted a comment from Z4nzu Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants