# import code for encoding urls and generating md5 hashes
import urllib, hashlib
# Set your variables here
email = "someone@somewhere.com"
default = "https://www.example.com/default.jpg"
size = 40
# construct the url
cravatar_url = "https://cravatar.cn/avatar/" + hashlib.md5(email.lower()).hexdigest() + "?"
cravatar_url += urllib.urlencode({'d':default, 's':str(size)})
如果您使用 Python 3,请尝试 libgravatar (调整为 libcravatar 即可) 。这是第三方库,不受 Cravatar 官方支持。