Convert curl example to pycurl

Question:

Could someone convert the following PostMark curl example to pycurl?

curl -X POST "http://api.postmarkapp.com/email" 
-H "Accept: application/json" 
-H "Content-Type: application/json" 
-H "X-Postmark-Server-Token: ed742D75-5a45-49b6-a0a1-5b9ec3dc9e5d" 
-v 
-d "{From: '[email protected]', To: '[email protected]', Subject: 'Postmark test', HtmlBody: '<html><body><strong>Hello</strong> dear Postmark user.</body></html>'}"
Asked By: Darth

||

Answers:

You can use something like this. It’s a basic implementation but it should work.

import pycurl, json

postmark_url = 'https://api.postmarkapp.com/email'

data = json.dumps({"From": "[email protected]", "To": "[email protected]", "Subject": "Pycurl", "TextBody": "Some text"})

c = pycurl.Curl()
c.setopt(pycurl.URL, github_url)
c.setopt(pycurl.HTTPHEADER, ['X-Postmark-Server-Token: API_TOKEN_HERE','Accept: application/json'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
c.perform()
Answered By: JP Toto
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.