Closed meetmangukiya closed 3 years ago
I guess there should be a check that the response contains the used keys, if it doesn't set sane empty values?
The code raises an exception when the result can be considered as a table formatted result. for instance: searching for "wet country", for the script there is no pod "result". I make a request for only input interpretation and result pod and if i try accessing the result via pods[1], it gives me an index out of bounds exception.
Contributions are welcome.
I just gave this a try.
wolframalpha main $ .tox/python/bin/python
Python 3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wolframalpha as wa
>>> cl = wa.Client.from_env()
>>> res = cl.query('this is a sentence')
>>> res
{'@success': 'false', '@error': 'false', '@numpods': '0', '@datatypes': '', '@timedout': '', '@timedoutpods': '', '@timing': '1.195', '@parsetiming': '0.511', '@parsetimedout': 'false', '@recalculate': '', '@id': '', '@parseidserver': '41', '@host': 'https://www5b.wolframalpha.com', '@server': '41', '@related': '', '@version': '2.6', 'didyoumeans': {'@count': '1', 'didyoumean': {'@score': '0.361698', '@level': 'medium', '#text': 'sentence'}}}
>>> res.pods
Traceback (most recent call last):
File "/Users/jaraco/code/main/wolframalpha/wolframalpha/__init__.py", line 150, in __getattr__
val = self[name] if name in self else self[attr_name]
KeyError: '@pods'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jaraco/code/main/wolframalpha/wolframalpha/__init__.py", line 152, in __getattr__
raise AttributeError(name)
AttributeError: pods
>>> res.success
'false'
It looks like the query returned a non-success result and numpods
is '0', so I wouldn't expect pods
to be useful here. Probably the library could provide a nicer interface.
if pods key is accessed, then it raises a KeyError
if the response is accessed, it raises
KeyError
as well