So im trying to make a script that finds a random word from dictionaryapi and returns the word and its defenition. The problems start at the line labeled "this is the broken line" if used print statements to test and everything before that line works smoothly, ive done print(word) and it prints a random word each time, so the problem is that line im pretty sure. Help please
import requests
def random_word_definition():
try:
word_response = requests.get("https://random-word-api.herokuapp.com/word?number=1")
word_response.raise_for_status()
word = word_response.json()[0]
dic_response = requests.get(f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}") # this is the broken line
if dic_response.status_code != 200:
return None
dic_data = dic_response.json()
dic_definition = dic_data[0]["meanings"][0]["definitions"][0]["definition"]
return "{word}: {dic_definition}"
except Exception as e:
print("Error:", e)
return None