Errors when doing an exception with requests in python
I've been searching for the reason behind my issue to no avail. It worked before I added the exception handler so I'm relatively perplexed. I am new to python, JSON, APIs, and sql, but not to programming.
def getSyllables(word): conn = sqlite3.connect("wordbase.db") c = conn.cursor() c.execute('SELECT * FROM words WHERE Word =?', [word]) syllables = 0 if (c.fetchone() == None): url = 'http://rhymebrain.com/talk?function=getWordInfo&word=' + word try: r = requests.get(url) j = json.loads(r.text) rememberSyllables(word, int(j['syllables']) syllables = int(j['syllables']) except requests.exceptions.RequestException as e: syllables = 0 else: syllables = c.fetchone return syllables
The error I get now is:
syllables = int(j['syllables']) ^ SyntaxError: invalid syntax
And if I remove that (Even though I'm fairly certain that the syntax is correct?):
except requests.exceptions.RequestException: ^ SyntaxError: invalid syntax
The problem is very simple, you haven't closed the previous line's parentheses:
This should solve the problem.
rememberSyllables(word, int(j['syllables'])) Here the extra ) would solve the issue!!