2014-04-02 16 views
11

Konnte jemand das folgende PostMark Curl-Beispiel zu Pycurl konvertieren?Convert Curl-Beispiel zu 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>'}" 
+0

Ich kann, aber ich werde nicht. Zeigen Sie Ihren Code, ich werde ändern. Es ist einfacher für mich. –

Antwort

26

Sie können so etwas verwenden. Es ist eine grundlegende Implementierung, aber es sollte funktionieren.

import pycurl, json 

github_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() 
+3

Sehr ordentliches und einfaches Beispiel. Hat mir viel geholfen :) – dhruvvyas90