Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Find a Github user's email address
__author__ = 'Khaled Monsoor <>'
__license__ = 'The MIT License: <>'
import requests
import json
def github_username_to_email(username):
Given a valid Github username, this function returns the users email address.
If `username` is invalid on, it will raise ValueError.
If `username` is valid but the user's email-address is not public,
an empty string('') will be returned.
api_url = ''
hit_url = api_url + str(username)
response = requests.get(hit_url)
if response.status_code != 200:
raise ValueError('Invalid username: {}'.format(username))
user = json.loads(response.content)
return user['email'] if user['email'] else ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment