Skip to content

Instantly share code, notes, and snippets.

@nikhilkumarsingh
Created April 17, 2017 06:31
Show Gist options
  • Save nikhilkumarsingh/5afed5a8c2371626620ea376ce795994 to your computer and use it in GitHub Desktop.
Save nikhilkumarsingh/5afed5a8c2371626620ea376ce795994 to your computer and use it in GitHub Desktop.
Demo python script to interact with Wit.ai app using a Python Client
from wit import Wit
access_token = "server_access_token_here"
client = Wit(access_token = access_token)
message_text = "i live in Australia"
resp = client.message(message_text)
print(resp)
@chvrajput
Copy link

Receiving Error while running utils.py
resp = client.message(message_text)
File "/usr/local/lib/python2.7/dist-packages/wit/wit.py", line 82, in message
resp = req(self.logger, self.access_token, 'GET', '/message', params)
File "/usr/local/lib/python2.7/dist-packages/wit/wit.py", line 37, in req
**kwargs
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))

@chvrajput
Copy link

chvrajput commented Oct 10, 2017

Error is still same!!
Is any message API is calling and how?

@jalees01
Copy link

hey it throws me an error: no module named wit,i have installed wit...what to do???where I am doing wrong??

@nikhilkumarsingh
Copy link
Author

@jalees01 have you put wit in your requirements.txt file?

@AzmayenFayek
Copy link

I installed wit using pip install wit. then again redeploy on heroku.
here is the terminal
(myvenv) D:\MamaBot>pip install wit
Requirement already satisfied: wit in d:\mamabot\myvenv\lib\site-packages (6.0.0)
Requirement already satisfied: requests>=0.8.8 in d:\mamabot\myvenv\lib\site-packages (from wit) (2.25.0)
Requirement already satisfied: prompt-toolkit in d:\mamabot\myvenv\lib\site-packages (from wit) (3.0.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\mamabot\myvenv\lib\site-packages (from requests>=0.8.8->wit) (1.26.2)
Requirement already satisfied: chardet<4,>=3.0.2 in d:\mamabot\myvenv\lib\site-packages (from requests>=0.8.8->wit) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in d:\mamabot\myvenv\lib\site-packages (from requests>=0.8.8->wit) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in d:\mamabot\myvenv\lib\site-packages (from requests>=0.8.8->wit) (2020.11.8)
Requirement already satisfied: wcwidth in d:\mamabot\myvenv\lib\site-packages (from prompt-toolkit->wit) (0.2.5)

(myvenv) D:\MamaBot>pip freeze > requirements.txt

(myvenv) D:\MamaBot>git init
Reinitialized existing Git repository in D:/MamaBot/.git/

(myvenv) D:\MamaBot>git status
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: utils.py

no changes added to commit (use "git add" and/or "git commit -a")

(myvenv) D:\MamaBot>git add .

(myvenv) D:\MamaBot>git status
On branch master
Changes to be committed:
(use "git restore --staged ..." to unstage)
modified: utils.py

(myvenv) D:\MamaBot>git commit -m "initial commit"
[master 4c91ccd] initial commit
1 file changed, 1 insertion(+), 1 deletion(-)

(myvenv) D:\MamaBot>heroku git:remote -a frozen-gorge-43617
set git remote heroku to https://git.heroku.com/frozen-gorge-43617.git

(myvenv) D:\MamaBot>git push heroku master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 293 bytes | 48.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> No change in requirements detected, installing from cache
remote: -----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 47M
remote: -----> Launching...
remote: Released v11
remote: https://frozen-gorge-43617.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/frozen-gorge-43617.git
0c00b45..4c91ccd master -> master

(myvenv) D:\MamaBot>python app.py
Traceback (most recent call last):
File "app.py", line 3, in
from utils import wit_response
File "D:\MamaBot\utils.py", line 1, in
from wit import Wit
ModuleNotFoundError: No module named 'wit'

am I doing any wrong??
please help me
requirements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment