{"action":"created","issue":{"url":"https://api.github.com/repos/sendgrid/sendgrid-python/issues/270","repository_url":"https://api.github.com/repos/sendgrid/sendgrid-python","labels_url":"https://api.github.com/repos/sendgrid/sendgrid-python/issues/270/labels{/name}","comments_url":"https://api.github.com/repos/sendgrid/sendgrid-python/issues/270/comments","events_url":"https://api.github.com/repos/sendgrid/sendgrid-python/issues/270/events","html_url":"https://github.com/sendgrid/sendgrid-python/issues/270","id":190051150,"number":270,"title":"PDF file attachment Error 400","user":{"login":"JonathanVandal","id":18136331,"avatar_url":"https://avatars.githubusercontent.com/u/18136331?v=3","gravatar_id":"","url":"https://api.github.com/users/JonathanVandal","html_url":"https://github.com/JonathanVandal","followers_url":"https://api.github.com/users/JonathanVandal/followers","following_url":"https://api.github.com/users/JonathanVandal/following{/other_user}","gists_url":"https://api.github.com/users/JonathanVandal/gists{/gist_id}","starred_url":"https://api.github.com/users/JonathanVandal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonathanVandal/subscriptions","organizations_url":"https://api.github.com/users/JonathanVandal/orgs","repos_url":"https://api.github.com/users/JonathanVandal/repos","events_url":"https://api.github.com/users/JonathanVandal/events{/privacy}","received_events_url":"https://api.github.com/users/JonathanVandal/received_events","type":"User","site_admin":false},"labels":[{"id":378654181,"url":"https://api.github.com/repos/sendgrid/sendgrid-python/labels/status:%20help%20wanted","name":"status: help wanted","color":"e99695","default":false},{"id":290033,"url":"https://api.github.com/repos/sendgrid/sendgrid-python/labels/type:%20enhancement","name":"type: enhancement","color":"84b6eb","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-17T13:47:22Z","updated_at":"2016-11-18T08:49:23Z","closed_at":null,"body":"#### Issue Summary\r\n\r\nI'm trying to attach a PDF file to my email sent with sendgrid. But the Sendgrid Python library is throwing an error HTTP Error 400: Bad Request.\r\n\r\n#### Steps to Reproduce\r\n\r\nHere is my code :\r\n\r\n```\r\nsg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))\r\n\r\nfrom_email = Email(\"from@example.com\")\r\nsubject = \"subject\"\r\nto_email = Email(\"to@example.com\")\r\ncontent = Content(\"text/html\", email_body)\r\n\r\npdf = open(pdf_path, \"rb\").read().encode(\"base64\")\r\nattachment = Attachment()\r\nattachment.set_content(pdf)\r\nattachment.set_type(\"application/pdf\")\r\nattachment.set_filename(\"test.pdf\")\r\nattachment.set_disposition(\"attachment\")\r\nattachment.set_content_id(number)\r\n\r\nmail = Mail(from_email, subject, to_email, content)\r\nmail.add_attachment(attachment)\r\n\r\nresponse = sg.client.mail.send.post(request_body=mail.get())\r\n\r\nprint(response.status_code)\r\nprint(response.body)\r\nprint(response.headers)\r\n```\r\n\r\nI think this is a problem due to the base64 encode \r\n\r\n`pdf = open(pdf_path, \"rb\").read().encode(\"base64\")`\r\n\r\nI tried with this line to test : https://github.com/sendgrid/sendgrid-python/blob/ca96c8dcd66224e13b38ab8fd2d2b429dd07dd02/examples/helpers/mail/mail_example.py#L66\r\n\r\nAnd it works. But when I'm using my PDF base64 encoded I have the error 400\r\n\r\n#### Technical details:\r\n\r\n* sendgrid-python Version: master latest commit\r\n* Python Version: 2.7.9"},"comment":{"url":"https://api.github.com/repos/sendgrid/sendgrid-python/issues/comments/261479152","html_url":"https://github.com/sendgrid/sendgrid-python/issues/270#issuecomment-261479152","issue_url":"https://api.github.com/repos/sendgrid/sendgrid-python/issues/270","id":261479152,"user":{"login":"JonathanVandal","id":18136331,"avatar_url":"https://avatars.githubusercontent.com/u/18136331?v=3","gravatar_id":"","url":"https://api.github.com/users/JonathanVandal","html_url":"https://github.com/JonathanVandal","followers_url":"https://api.github.com/users/JonathanVandal/followers","following_url":"https://api.github.com/users/JonathanVandal/following{/other_user}","gists_url":"https://api.github.com/users/JonathanVandal/gists{/gist_id}","starred_url":"https://api.github.com/users/JonathanVandal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonathanVandal/subscriptions","organizations_url":"https://api.github.com/users/JonathanVandal/orgs","repos_url":"https://api.github.com/users/JonathanVandal/repos","events_url":"https://api.github.com/users/JonathanVandal/events{/privacy}","received_events_url":"https://api.github.com/users/JonathanVandal/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T08:49:23Z","updated_at":"2016-11-18T08:49:23Z","body":"Hi, I filled out the form thank you so much.\r\n\r\nIt's a good idea to put this snippet for the attachment. "}}
{"actor":{"display_login":"JonathanVandal"}}