tags:

views:

27

answers:

1

Having way too much trouble making this cmd line curl statement work in python script...help! Attempting to use URLLIB.

curl -X POST "http://api.postmarkapp.com/email" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Postmark-Server-Token: abcdef-1234-46cc-b2ab-38e3a208ab2b" \
-v \
-d "{From: '[email protected]', To: '[email protected]', Subject: 'Postmark test', HtmlBody: 'Hello dear Postmark user.'}"

+1  A: 

Ok so you should probably user urllib2 to submit the actual request but here is the code:

import urllib
import urllib2

url = "http://api.postmarkapp.com/email"
data = "{From: '[email protected]', To: '[email protected]', Subject:   'Postmark test', HtmlBody: 'Hello dear Postmark user.'}"
headers = { "Accept" : "application/json",
        "Conthent-Type": "application/json",
        "X-Postmark-Server-Token": "abcdef-1234-46cc-b2ab-38e3a208ab2b"}
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
the_page = response.read()

Check out: urllib2 the unwritten manual

I get a 401 unauthorized response so I guess it works :)

Joshkunz
you rock...thanks!
Scott
@scott no problem :)
Joshkunz