将curl示例转换为pycurl [英] Convert curl example to pycurl

查看:173
本文介绍了将curl示例转换为pycurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以将以下PostMark curl示例转换为pycurl?

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>'}"


推荐答案

你可以使用这样的东西。这是一个基本的实现,但它应该工作。

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

import pycurl, json

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

这篇关于将curl示例转换为pycurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆