import requests


def get_keybase_pubkey(username):
    """
    Return the base64 encoded public PGP key for a keybase user.
    """
    # Retrieve the text of the public key stored in Keybase
    user = requests.get('https://keybase.io/{username}/key.asc'.format(
        username=username))
    # Explicitly raise an exception if there is an HTTP error. No-op on success
    user.raise_for_status()
    # Process the key to only include the contents and not the wrapping
    # contents (e.g. ----BEGIN PGP KEY---)
    key_lines = user.text.strip('\n').split('\n')
    key_lines = key_lines[key_lines.index(''):-2]
    return ''.join(key_lines)