Skip to content

Instantly share code, notes, and snippets.

@urlbox
Last active December 13, 2015 20:38
Show Gist options
  • Save urlbox/4971000 to your computer and use it in GitHub Desktop.
Save urlbox/4971000 to your computer and use it in GitHub Desktop.
urlbox python
#!/usr/bin/python
import hmac
from hashlib import sha1
import urllib
def urlbox(key, secret, url, args):
qs = urllib.urlencode(dict(url=url, **args))
signature = hmac.new(secret, qs, sha1)
token = signature.digest().encode('hex')
return "https://api.urlbox.io/v1/%s/%s/png?%s" % (key, token, qs)
argsDict = {'url' : "google.com", 'width': 1024, 'height': 768};
print urlbox ("google.com", argsDict)
@matiskay
Copy link

There is a problem on line 23. It should be

print urlbox("google.com", argsDict)

I think you have to maintain the indentation to 4 spaces.

@ankona
Copy link

ankona commented Aug 10, 2015

The code at line 9 breaks for me with an error that the argument URL is recieved multiple times by urlencode().

I switched to this to make it work:

    args = {'url' : url, 'width': 800, 'full_page': True};
    qs = urllib.urlencode(dict(**args))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment