jaraco / wolframalpha

MIT License
148 stars 25 forks source link

Wolfram Alpha Dictionary Element Problem #25

Closed EthanChenster closed 3 years ago

EthanChenster commented 3 years ago

Im trying to make a wolfram alpha assistant and I got this error

Code:

import wolframalpha
import ssl
app_id = 'REDACTED'
wolframbot = wolframalpha.Client(app_id)
res = wolframbot.query('Temperature in Las Vegas Nevada')
for pod in res.pods:
    print(pod.subpods)
    for sub in pod.subpods:
        print(sub.plainText)

Error:

<map object at 0x7ff848b35be0>
Traceback (most recent call):
   file "main.py", line 9 in <module> 
      for sub in pod.subpods:
ValueError: dictionary update sequence element #0 has length 1; 2 is required

Is there any solution?

Thierryonre commented 3 years ago

I think WolframAlpha may have changed their API format again since the given format is now a dictionary. Therefore, you can use the following code to access the plaintext element: for pod in res.pods: print(pod["subpod"]["plaintext"])

Maybe @jaraco should check if this applies in all cases?

EthanChenster commented 3 years ago

I think WolframAlpha may have changed their API format again since the given format is now a dictionary. Therefore, you can use the following code to access the plaintext element: for pod in res.pods: print(pod["subpod"]["plaintext"])

Maybe @jaraco should check if this applies in all cases?

Wait what should my code look like?

Thierryonre commented 3 years ago

@ScottyEthan, here's the code with the updated section:

import wolframalpha
import ssl
app_id = 'REDACTED'
wolframbot = wolframalpha.Client(app_id)
res = wolframbot.query('Temperature in Las Vegas Nevada')
for pod in res.pods:
    print(pod["subpod"]["plaintext"])

Happy coding :D

EthanChenster commented 3 years ago

Thanks!

Harmon758 commented 3 years ago

See #26