I'm new to the Wolfram|Alpha API for python and I could not find much help on the internet, so I turned to stack overflow. I receive the "NameError: name 'pod' is not defined" on SOME queries on Wolfram|Alpha. Any help would be much appreciated. When I input my query "Length of a Ferrari 458" I used to end up with the StopIteration error, now I've change the code to use "pods" method. Now I get a NameError. The out put should give me the length of the car (https://www.wolframalpha.com/input/?i=length+of+ferrari+458) I had to x out app_id as it's not mine, sorry for the inconvenience.
#!/usr/bin/python
import wolframalpha
app_id=('xxxxxx-xxxxxxxxxx')
client = wolframalpha.Client(app_id)
query = input("Query:")
if len(res.pods) > 0:
texts = ""
pod = res.pods[1]
if pod.text:
texts = pod.text
else:
texts = "I have no answer for that"
texts = texts.encode('ascii', 'ignore')
print (texts)
The error I get:
Query: length of ferrari 458
Traceback (most recent call last):
File "Wolfram.py", line 24, in <module>
if pod.text:
NameError: name 'pod' is not defined