-2

Okay so I'm programming a Wolfram Alpha API and I added a res string with query and its giving me this error: AttributeError: 'str' object has no attribute 'query' Here's the PyDa.py:

import PySimpleGUI as sg                       
sg.theme('Dark Blue')

    app_id = ('API_key')
    client = (app_id)


layout = [  [sg.Text("Hello, my name's Ted. What's your question?")],   
        [sg.Input()],
        [sg.Button('Ok'), sg.Button('Cancel')] ]


window = sg.Window('Ted', layout)      


while True:
event, values = window.read()   
if event in (None, 'Cancel'):
        break


res = client.query(values[0])
print(next(res.results).text)




window.close()        

where values[0] is what the user enters. I've tried completely deleting query and it doesn't work. I thing I need to install something but when I try pip install wolframalpha api it does install but that's not whats missing/ is wrong. I should be getting pods but its not sending those because of the error.

TedDev
  • 3
  • 2

1 Answers1

1

Hmm, I don't know exactly what happens before the client.query call, but the AtrributeError says client is of type str. I don't think there is a problem with dependencies, because then the error would be different. The client is according to the docs defined with client = Client(getfixture('API_key')). If you have this in your code, then I have no idea what's wrong.

Morbotu
  • 31
  • 1
  • if I add the ```Client(getfixture('API_key'))```it says Client is not defined – TedDev Jan 22 '22 at 17:08
  • Also I'll add whats before rq – TedDev Jan 22 '22 at 17:10
  • 1
    You need to import wolfram before calling Client. So start the file with `from wolframalpha import *` or `from wolframalpha import Client` to just import client. Then you can call `client = Client(getfixture('API_key'))`. – Morbotu Jan 22 '22 at 17:26
  • As I've said it doesn't work to install it. – TedDev Jan 23 '22 at 00:42
  • Ok I've had to fix a bit of my code this was the right answer – TedDev Jan 23 '22 at 02:00
  • actually no it isn't getfixture doesn't work – TedDev Jan 23 '22 at 02:03
  • @TedDev You can't just use functions that you've neither defined nor [imported](https://realpython.com/python-import/). Maybe you should take a look at some [Wolfram Alpha Python tutorials](https://www.geeksforgeeks.org/python-create-a-simple-assistant-using-wolfram-alpha-api/) to see how it's used. – CrazyChucky Jan 23 '22 at 02:18
  • I was actually going through that right now @CrazyChucky I was trouble shooting it and I'm looking for how to properly import it thanks for confirming it's there – TedDev Jan 23 '22 at 02:29