import hashlib
from urllib.parse import urlencode
# Set your variables here
email = "someone@somewhere.com"
default = "https://www.example.com/default.jpg"
size = 40
# Encode the email to lowercase and then to bytes
email_encoded = email.lower().encode('utf-8')
# Generate the SHA256 hash of the email
email_hash = hashlib.sha256(email_encoded).hexdigest()
# Construct the URL with encoded query parameters
query_params = urlencode({'d': default, 's': str(size)})
gravatar_url = f"https://www.gravatar.com/avatar/{email_hash}?{query_params}"
print(gravatar_url)
REST API
Mobile SDKs
Guides
Developer tools
Python
- Developing with an AI assistant? Use these custom instructions.
- Use of our free APIs is governed by the Guidelines for Responsible Use.
- Documentation is licensed under Creative Commons BY-SA 4.0.
Last updated on:
