Regular JSON Curl to pyCurl

590 views Asked by At

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.

1

There are 1 answers

0
Gutz-Pilz On BEST ANSWER
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!