Guest User

Untitled

a guest
Mar 27th, 2018
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import MySQLdb
  2. import sendgrid
  3. import os
  4. from sendgrid.helpers.mail import *
  5.  
  6. def sendalert(alertbody):
  7. sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SG.---....'#Not revealing my API key))
  8. from_email = Email("abcd@gmail.com")
  9. to_email = Email("abcd@gmail.com")
  10. subject = "Zomato Negative review"
  11. content = Content(alertbody)
  12. mail = Mail(from_email, subject, to_email, content)
  13. response = sg.client.mail.send.post(request_body=mail.get())
  14. print(response.status_code)
  15. print(response.body)
  16. print(response.headers)
  17.  
  18. Traceback (most recent call last):
  19. File "zomato.py", line 91, in <module>
  20. readreview(input_text)
  21. File "zomato.py", line 64, in readreview
  22. sendalert(review_text) # sending the email alert
  23. File "zomato.py", line 16, in sendalert
  24. response = sg.client.mail.send.post(request_body=mail.get())
  25. File "/Library/Python/2.7/site-packages/python_http_client-2.2.1- py2.7.egg/python_http_client/client.py", line 204, in http_request
  26. return Response(self._make_request(opener, request))
  27. File "/Library/Python/2.7/site-packages/python_http_client-2.2.1-py2.7.egg/python_http_client/client.py", line 138, in _make_request
  28. return opener.open(request)
  29. File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
  30. response = meth(req, response)
  31. File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
  32. 'http', request, response, code, msg, hdrs)
  33. File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
  34. return self._call_chain(*args)
  35. File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
  36. result = func(*args)
  37. File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
  38. raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
  39.  
  40. import os
  41. import sendgrid
  42.  
  43.  
  44. def sendalert(alertbody):
  45. sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SG.---....'#Not revealing my API key))
  46.  
  47. message = sendgrid.Mail()
  48. message.add_to("abcd@gmail.com")
  49. message.set_from("abcd@gmail.com")
  50. message.set_subject("Zomato Negative review")
  51. message.set_text(alertbody)
  52.  
  53. sg.send(message)
Add Comment
Please, Sign In to add comment