import requests
import json


def shakespeare_api(text):
    """
    Shakespeare API function to retrieve the translation.
    """

    api_params = {"text" : text}
    response = requests.post('https://api.funtranslations.com/translate/shakespeare.json', data=api_params) # headers=headers, data=data

    # Check for errors in response
    if "error" not in response.text.lower():
        response_dict = json.loads(response.text)
        shakespeare_description = response_dict["contents"]["translated"]
        return shakespeare_description
    else:
        error_text = response.text
        return error_text