Convert curl example to pycurl

眉间皱痕 提交于 2019-12-17 23:18:47

问题


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: 'sender@example.com', To: 'receiver@example.com', Subject: 'Postmark test', HtmlBody: '<html><body><strong>Hello</strong> dear Postmark user.</body></html>'}"

回答1:


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": "user@example.com", "To": "receiver@example.com", "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()


来源:https://stackoverflow.com/questions/22799648/convert-curl-example-to-pycurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!