【问题标题】:Regular JSON Curl to pyCurl常规 JSON 卷曲到 pyCurl
【发布时间】:2015-09-09 14:16:57
【问题描述】:

我想让这个 curl 命令在 Python 脚本中运行

curl -H "public-api-token: 049cxxxxxc026ef7364fa38c8792" -X PUT -d "urlToShorten=google.com" https://api.shorte.st/v1/data/url

但我现在知道怎么做。

【问题讨论】:

标签: python json bash curl pycurl


【解决方案1】:
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')

还是谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 2017-05-10
    • 2017-04-09
    • 2012-01-21
    • 2018-07-08
    • 2019-09-18
    • 2016-08-12
    • 2011-05-15
    相关资源
    最近更新 更多