gpt4 book ai didi

python-2.7 - 将curl示例转换为pycurl

转载 作者:行者123 更新时间:2023-12-03 21:16:55 25 4
gpt4 key购买 nike

有人可以将以下PostMark curl示例转换为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>'}"

最佳答案

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

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

关于python-2.7 - 将curl示例转换为pycurl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22799648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com