2017-07-15 84 views
0

只是試圖用Wit.ai & Python進行實驗,但得到以下錯誤。我在這裏做錯了什麼?'Wit'對象沒有任何屬性'message'

錯誤:

Traceback (most recent call last): 
File "C:/Python27/mx1.py", line 7, in <module> 
resp = client.message(my_message) 
AttributeError: 'Wit' object has no attribute 'message' 

代碼:

from wit import Wit 
access_token='B3GHXHLTXIASO7S4KY7UC65LMSTCDEHK' 
client = Wit(access_token) 
my_message='who are you?' 
resp = client.message(my_message) 
print(resp) 
+0

你的例子對我來說工作得很好(響應包含'我是Jarvis'),但我在Linux上。你能告訴我們你是如何安裝Wit庫的? – randomir

+0

我在Win10上運行Python 2.7。我使用「pip install pywit」進行安裝。 – user3289968

+0

[docs](https://github.com/wit-ai/pywit#install)說'pip install wit'。 – randomir

回答

1

所以,好像你正在使用Python pywit package, last updated on 2015-11-07 (version 0.4.0)的舊(實際上unofficial)版本。

您應該刪除pywit包並安裝wit,就像他們說,在docs/install部分:

pip uninstall pywit 
pip install wit 

只是爲了保持完整性,如果你看一下您的舊pywit包的wit.pypython2.7/site-packages/wit/wit.py內內,您會看到類Wit的定義,使用get_message()而不是當前的message()。所以,在pywit,你的代碼將運行,如果你說:的

resp = client.get_message(my_message) 

代替

resp = client.message(my_message) 

但你真的應該切換到當前(官方)版本。

+0

非常感謝! – user3289968

+0

不客氣! – randomir