cjaiello / Slack-Standup-Report-Bot

Python, Flask, Postgres, Slack API, Heroku. Set a daily standup time, have bot message in a channel requesting daily standup reports, and optionally have your standup report be emailed to a specified email address each day. Has instructions for local setup and Heroku setup.
4 stars 4 forks source link

Fix bug where standup messages with fancy double quotes can't be encoded #27

Open cjaiello opened 4 years ago

cjaiello commented 4 years ago

To reproduce, send a response to the bot's standup call, and in that message have double quotes.

When we try to send the email, you'll see:

2020-09-21T02:39:00.118526+00:00 app[web.1]: [2020-09-20 22:39:00][INFO] Final standup results: ['christinajaiello: Okay now let’s see if this is emailed to me and also if we get the “time has run out” message for submission; \n']
2020-09-21T02:39:00.118601+00:00 app[web.1]: [2020-09-20 22:39:00][INFO] Email info: general | EMAIL_ADDRESS_HERE | christinajaiello: Okay now let’s see if this is emailed to me and also if we get the “time has run out” message for submission;
2020-09-21T02:39:00.118602+00:00 app[web.1]: 
2020-09-21T02:39:00.356394+00:00 app[web.1]: [2020-09-20 22:39:00][INFO] Username is slackstandupbottestemail@gmail.com
2020-09-21T02:39:00.356411+00:00 app[web.1]: [2020-09-20 22:39:00][INFO] Subject: #general Standup Report
2020-09-21T02:39:00.356412+00:00 app[web.1]: 
2020-09-21T02:39:00.356413+00:00 app[web.1]: christinajaiello: Okay now let’s see if this is emailed to me and also if we get the “time has run out” message for submission;
2020-09-21T02:39:00.356413+00:00 app[web.1]: 
2020-09-21T02:39:00.358749+00:00 app[web.1]: Job "get_timestamp_and_send_email (trigger: cron[day_of_week='mon-sun', hour='22', minute='39'], next run at: 2020-09-21 22:39:00 EDT)" raised an exception
2020-09-21T02:39:00.358750+00:00 app[web.1]: Traceback (most recent call last):
2020-09-21T02:39:00.358751+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/apscheduler/executors/base.py", line 125, in run_job
2020-09-21T02:39:00.358751+00:00 app[web.1]: retval = job.func(*job.args, **job.kwargs)
2020-09-21T02:39:00.358751+00:00 app[web.1]: File "/app/app.py", line 320, in get_timestamp_and_send_email
2020-09-21T02:39:00.358752+00:00 app[web.1]: email_client.send_email(a_channel_name, recipient_email_address, formatted_standup_message, "Standup Report")
2020-09-21T02:39:00.358752+00:00 app[web.1]: File "/app/email_client.py", line 21, in send_email
2020-09-21T02:39:00.358752+00:00 app[web.1]: server.sendmail(os.environ['USERNAME'], recipient_email_address, message)
2020-09-21T02:39:00.358753+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/smtplib.py", line 859, in sendmail
2020-09-21T02:39:00.358753+00:00 app[web.1]: msg = _fix_eols(msg).encode('ascii')
2020-09-21T02:39:00.358753+00:00 app[web.1]: UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 66: ordinal not in range(128)

Example:

Screen Shot 2020-09-20 at 10 43 06 PM

https://slackstandupb-lnv3162.slack.com/archives/C01AZV5LTNY/p1600655901004900?thread_ts=1600655880.004800&cid=C01AZV5LTNY

besnardf commented 4 years ago

Hi @cjaiello

2020-09-21T02:39:00.358753+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/smtplib.py", line 859, in sendmail
2020-09-21T02:39:00.358753+00:00 app[web.1]: msg = _fix_eols(msg).encode('ascii')

What if you change msg = _fix_eols(msg).encode('ascii') to msg = _fix_eols(msg).encode('utf-8') ?