常规 JSON 卷曲到 pyCurl

Regular JSON Curl to pyCurl

我想在 Python 脚本

中将此 curl 命令发送到 运行
curl -H "public-api-token: 049cxxxxxc026ef7364fa38c8792" -X PUT -d "urlToShorten=google.com" https://api.shorte.st/v1/data/url

但我现在知道怎么做了。

def make_tiny(url):
    connection = httplib.HTTPSConnection('api.shorte.st', 443)
    connection.connect()
    connection.request('PUT', '/v1/data/url', json.dumps({
           "urlToShorten": url,
         }), {
           "public-api-token": "049cd75ad7axxx26ef7364fa38c8792",
           "Content-Type": "application/json"
         })
    results = json.loads(connection.getresponse().read())
    return results.get("shortenedUrl", "none").decode('utf-8')

谢谢!