简体   繁体   中英

Regular JSON Curl to pyCurl

I'd like to get this curl command to run in a Python Script

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

but I have now clue how.

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

Thanks anyway!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM