title: Python Sendgrid send email with PDF attachment file
body: <p>I'm trying to attach a PDF file to my email sent with sendgrid.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
  
  from_email = Email("from@example.com")
  subject = "subject"
  to_email = Email("to@example.com")
  content = Content("text/html", email_body)
  
  pdf = open(pdf_path, "rb").read().encode("base64")
  attachment = Attachment()
  attachment.set_content(pdf)
  attachment.set_type("application/pdf")
  attachment.set_filename("test.pdf")
  attachment.set_disposition("attachment")
  attachment.set_content_id(number)
  
  mail = Mail(from_email, subject, to_email, content)
  mail.add_attachment(attachment)
  
  response = sg.client.mail.send.post(request_body=mail.get())
  
  print(response.status_code)
  print(response.body)
  print(response.headers)
  </code></pre>
  
  <p>But the Sendgrid Python library is throwing an error HTTP Error 400: Bad Request. </p>
  
  <p>What is wrong with my code ?</p>