python - 有人知道处理 Wolfram Alpha 和 Python 吗?
问题描述
下面是我的脚本:
import wolframalpha
client = wolframalpha.Client("LXP5A5-62XJKEY85U")
import PySimpleGUI as sg
sg.theme('DarkPurple') # Add a touch of color
# All the stuff inside your window.
layout = [ [sg.Text('Enter a command'), sg.InputText()],
[sg.Button('Ok'), sg.Button('Cancel')] ]
# Create the Window
window = sg.Window('Sunia', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
break
res = client.query(values[0])
try:
print (next(res.results).text)
except:
print ("No results")
window.close()
这是我的错误:
res = client.query(values[0])
File "C:\Users\jonathan b\AppData\Local\Programs\Python\Python38-32\lib\site-packages\wolframalpha\__init__.py", line 68, in query
assert resp.headers.gettype() == 'text/xml'
AttributeError: 'HTTPMessage' object has no attribute 'gettype'
解决方案
我想我理解你得到的错误非常简单,你只需将
client = wolframalpha.Client("LXP5A5-62XJKEY85U")放在sg.theme('DarkPurple')之前
import wolframalpha
import PySimpleGUI as sg
client = wolframalpha.Client("LXP5A5-62XJKEY85U")
sg.theme('DarkPurple') # Add a touch of color
# All the stuff inside your window.
layout = [ [sg.Text('Enter a command'), sg.InputText()],
[sg.Button('Ok'), sg.Button('Cancel')] ]
# Create the Window
window = sg.Window('Sunia', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
break
res = client.query(values[0])
try:
print (next(res.results).text)
except:
print ("No results")
window.close()
推荐阅读
- android - 需要帮助实现协程,需要等待api响应
- java - RecyclerView 中的横幅 AdMob
- kubernetes - 启用防火墙时无法访问 k8s-dashboard
- node.js - 不知道如何使用 dockerized clamAV 开始使用 nodejs
- rasa-nlu - 了解 RASA 表格
- xamarin - Xamarin.Forms 项目中的 Nuget 包已安装,但缺少参考
- nginx - Dynamix Nginx 代理传递,带有来自位置路径的变量
- python - 如何在按钮区域断开线路?
- c# - C# WPF - VLC - LibVLCSharp.Shared.VLCException:'未能加载所需的本机库
- python - 如何在服务器客户端 Python 中杀死子进程终端销售