airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Gallucci (JIRA)" <j...@apache.org>
Subject [jira] [Assigned] (AIRFLOW-2907) Sendgrid - Attachments - ERROR - Object of type 'bytes' is not JSON serializable
Date Thu, 16 Aug 2018 13:49:00 GMT

     [ https://issues.apache.org/jira/browse/AIRFLOW-2907?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Leo Gallucci reassigned AIRFLOW-2907:
-------------------------------------

    Assignee: Leo Gallucci  (was: Marcin Szymanski)

> Sendgrid - Attachments - ERROR - Object of type 'bytes' is not JSON serializable
> --------------------------------------------------------------------------------
>
>                 Key: AIRFLOW-2907
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-2907
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: contrib
>            Reporter: Leo Gallucci
>            Assignee: Leo Gallucci
>            Priority: Minor
>              Labels: sendgrid
>             Fix For: 2.0.0
>
>
> Attempting to attach files via Sendgrid operator always gives:
> {code}
> Sendgrid - Attachments - ERROR - Object of type 'bytes' is not JSON serializable
> {code}
> h4. How to reproduce:
> By setting files=['/nfs/somefile_to_attach.ipynb'] while using the EmailOperator
> {code}
> export AIRFLOW__EMAIL__EMAIL_BACKEND="airflow.contrib.utils.sendgrid.send_email"
> {code}
> {code}
> from airflow.operators.email_operator import EmailOperator
> email_task = EmailOperator(
>     task_id='email_task',
>     to="someone@hola.com", 
>     subject='This has an attachment',
>     html_content='this has an attachment',
>     files=['/nfs/somefile_to_attach.ipynb'],
>     dag=dag)
> {code}
> h4. Root cause
> Returned the encoded `bytes` type
> https://docs.python.org/3/library/base64.html#base64.b64encode
> However `attachment.content` expects a string.
> Problem is in this line:
> https://github.com/apache/incubator-airflow/blob/9d516c7134eb22a3c2fc63cf96626ef6e8b247f2/airflow/contrib/utils/sendgrid.py#L91
> {code}
> attachment.content = base64.b64encode(f.read())
> {code}
> h4. Solution via str()
> By googling the found solution was:
> https://stackoverflow.com/questions/47479205/e-mail-attachment-using-sendgird
> https://stackoverflow.com/questions/44933816/encode-csv-file-for-sendgrids-email-api/44934090
> {code}
> attachment.content = str(base64.b64encode(f.read()), 'utf-8')
> {code}
> I will send a PR



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message