Skip to content

Instantly share code, notes, and snippets.

@kpx-dev
Created November 20, 2014 19:55
Show Gist options
  • Save kpx-dev/fb740ba73d4c009732c5 to your computer and use it in GitHub Desktop.
Save kpx-dev/fb740ba73d4c009732c5 to your computer and use it in GitHub Desktop.
SendGrid block example with requests library
"""
This Python code snippet will show you how to get all SendGrid block records
Please change SG_USERNAME and SG_PASSWORD to match your credentials
install the amazing requests library
$ pip install requests==2.4.3
save this file as python block.py and run it
$ python block.py
"""
import requests
SG_USERNAME = ''
SG_PASSWORD = ''
SG_URL = "https://sendgrid.com/api"
if __name__ == '__main__':
block_url = "{}/blocks.get.json?api_user={}&api_key={}".format(
SG_URL, SG_USERNAME, SG_PASSWORD)
res = requests.get(block_url)
# Example output:
# [{u'status': u'4.0.0', u'reason': u'Unable to resolve MX host example.com: noerror', u'email': u'test@example.com'}]
print res.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment