I'm trying to make a simple QnA program using Python chatterbot.
# -*- coding: utf-8 -*-
from chatterbot import ChatBot
bot = ChatBot(
"SQLMemoryTerminal",
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function":
"chatterbot.comparisons.levenshtein_distance"
},
{
'import_path' : 'chatterbot.logic.LowConfidenceAdapter',
'threshold' : 0.3,
'default_response' : "Sorry. I can not find the exact answer."
},
'chatterbot.logic.multi_adapter.MultiLogicAdapter',
],
input_adapter="chatterbot.input.TerminalAdapter",
output_adapter="chatterbot.output.TerminalAdapter",
read_only= True
)
print("input question")
while True:
try:
print("Q : ",end="")
bot_input = bot.get_response(None)
except (KeyboardInterrupt, EOFError, SystemExit):
break
However, when I try to use the multiadapter function built in chatterbot, I get an error.
Traceback (most recent call last):
File "C:/Users/KPvoice/PycharmProjects/Contact/ChatterbotTest.py", line
30, in <module>
bot_input = bot.get_response(None)
File "C:\Python36\lib\site-packages\chatterbot\chatterbot.py", line 113,
in get_response
statement, response = self.generate_response(input_statement,
conversation_id)
File "C:\Python36\lib\site-packages\chatterbot\chatterbot.py", line 132,
in generate_response
response = self.logic.process(input_statement)
File "C:\Python36\lib\site-packages\chatterbot\logic\multi_adapter.py",
line 52, in process
output = adapter.process(statement)
File "C:\Python36\lib\site-packages\chatterbot\logic\multi_adapter.py",
line 89, in process
result.confidence = max_confidence
AttributeError: 'NoneType' object has no attribute 'confidence'
I do not know how to solve it.
The working environment is Windows 10, Python 3.7
The MultiLogicAdapter typically doesn't get used directly in this way.
Each logic adapter that you add to the logic_adapters=[] will get processed by the MultiLogicAdapter internally by ChatterBot, no need to explicitly specify it.
Related
`from scapy.all import *
from scapy.layers import http
def mysniff(interface):
sniff(iface=interface,store=False,prn=sniffed_packets)
def sniffed_packets(packet):
if packet.haslayer(http.HTTPRequest):
print(packet[http.HTTPRequest].Host + packet[http.HTTPRequest].Path)
if packet.haslayer(Raw):
load = packet[Raw].load
keys = ["username", "password", "pass", "email"]
for key in keys:
if key in load:
print(`load.encode`())
break
my sniff("Intel(R) 82574L Gigabit Network Connection")`
Want it to Print the Keys from the load that match the keywords as described above in the code. Although its executing the code and printing as expected but when I do an http login it displays the below error instead of printing the 'username' and 'password'.
Pls guide me as I am new to Python and Scapy.
Getting below error :
`Traceback (most recent call last):
File "sniff_packets.py", line 21, in <module>
mysniff("Intel(R) 82574L Gigabit Network Connection")
File "sniff_packets.py", line 5, in mysniff
sniff(iface=interface,store=False,prn=sniffed_packets)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\scapy-2.5.0.dev15-py3.8.egg\scapy\sendrecv.py", line 1310, in sniff
sniffer._run(*args, **kwargs)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\scapy-2.5.0.dev15-py3.8.egg\scapy\sendrecv.py", line 1253, in _run
session.on_packet_received(p)
` `File "C:\Program Files (x86)\Python38-32\lib\site-packages\scapy-2.5.0.dev15-py3.8.egg\scapy\sessions.py", line 109, in on_packet_received`
result = self. prn(pkt)`
File "sniff_packets.py", line 15, in sniffed_packets
if key in load:
`TypeError:` a bytes-like object is required, not 'str'``
```
`
I'm trying to make dictionary attack on zip file using Pool to increase speed.
But I face next error in Python 3.6, while it works in Python 2.7:
Traceback (most recent call last):
File "zip_crack.py", line 42, in <module>
main()
File "zip_crack.py", line 28, in main
for result in results:
File "/usr/lib/python3.6/multiprocessing/pool.py", line 761, in next
raise value
File "/usr/lib/python3.6/multiprocessing/pool.py", line 450, in _ handle_tasks
put(task)
File "/usr/lib/python3.6/multiprocessing/connection.py", line 206, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "/usr/lib/python3.6/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
TypeError: cannot serialize '_io.BufferedReader' object
I tried to search for same errors but couldn't find answer that can help here.
Code looks like this
def crack(pwd, f):
try:
key = pwd.strip()
f.extractall(pwd=key)
return True
except:
pass
z_file = zipfile.ZipFile("../folder.zip")
with open('words.dic', 'r') as passes:
start = time.time()
lines = passes.readlines()
pool = Pool(50)
results = pool.imap_unordered(partial(crack, f=z_file), lines)
pool.close()
for result in results:
if result:
pool.terminate()
break
pool.join()
I also tried another approach using map
with contextlib.closing(Pool(50)) as pool:
pool.map(partial(crack, f=z_file), lines)
which worked great and found passwords quickly in Python 2.7 but it throws same exception in python 3.6
I'm working on a project with the Intel Edison and Mini Breakout Board with Ubilinux and when trying commend: python uart.py I get:
root#ubilinux:~# python uart.py
Traceback (most recent call last):
File "uart.py", line 7, in <module>
u.setBaudRate(115200)
File "/usr/local/lib/i386-linux-gnu/python2.7/site-packages/mraa.py", line 1355, in <lambda>
__getattr__ = lambda self, name: _swig_getattr(self, Uart, name)
File "/usr/local/lib/i386-linux-gnu/python2.7/site-packages/mraa.py", line 78, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File "/usr/local/lib/i386-linux-gnu/python2.7/site-packages/mraa.py", line 73, in _swig_getattr_nondynamic
return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'
And here is the Python code:
import mraa
# Initialize UART
u=mraa.Uart(0)
# Set UART parameters
u.setBaudRate(115200)
u.setMode(8, mraa.UART_PARITY_NONE, 1)
u.setFlowcontrol(False, False)
# Start a neverending loop waiting for data to arrive.
# Press Ctrl+C to get out of it.
while True:
if u.dataAvailable():
# We are doing 1-byte reads here
data_byte = u.readStr(1)
print(data_byte)
# Just a two-way half-duplex communication example, "X" is a flag
if data_byte == "X":
u.writeStr("Yes, master!")
Can someone please help me fix this issue?
Thanks in advance
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
ckey=''
csecret=''
atoken=''
asecret=''
class listener(StreamListener):
def on_data(self,data):
print(data)
return True
def on_error(self,status):
print(status)
auth = OAuthHandler(ckey,csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track="cricket")
This code filter the twitter stream based on the filter. But I am getting following traceback after running the code. Can somebody please help
Traceback (most recent call last):
File "lab.py", line 23, in <module>
twitterStream.filter(track="car".strip())
File "C:\Python34\lib\site-packages\tweepy\streaming.py", line 430, in filter
self._start(async)
File "C:\Python34\lib\site-packages\tweepy\streaming.py", line 346, in _start
self._run()
File "C:\Python34\lib\site-packages\tweepy\streaming.py", line 286, in _run
raise exception
File "C:\Python34\lib\site-packages\tweepy\streaming.py", line 255, in _run
self._read_loop(resp)
File "C:\Python34\lib\site-packages\tweepy\streaming.py", line 298, in _read_loop
line = buf.read_line().strip()
File "C:\Python34\lib\site-packages\tweepy\streaming.py", line 171, in read_line
self._buffer += self._stream.read(self._chunk_size)
TypeError: Can't convert 'bytes' object to str implicitly
Im assuming you're using tweepy 3.4.0. The issue you've raised is 'open' on github (https://github.com/tweepy/tweepy/issues/615).
Two work-arounds :
1)
In streaming.py:
I changed line 161 to
self._buffer += self._stream.read(read_len).decode('UTF-8', 'ignore')
and line 171 to
self._buffer += self._stream.read(self._chunk_size).decode('UTF-8', 'ignore')
and then reinstalled via python3 setup.py install on my local copy of tweepy.
2)
remove the tweepy 3.4.0 module, and install 3.3.0 using command: pip install -I tweepy==3.3.0
Hope that helps,
-A
You can't do twitterStream.filter(track="car".strip()). Why are you adding the strip() it's serving no purpose in there.
track must be a str type before you invoke a connection to Twitter's Streaming API and tweepy is preventing that connection because you're trying to add strip()
If for some reason you need it, you can do track_word='car'.strip() then track=track_word, that's even unnecessary because:
>>> print('car'.strip())
car
Also, the error you're getting does not match the code you have listed, the code that's in your question should work fine.
When I run my program, I get the following error and am not sure on how to correct it. Can someone help with explaining what this error is and how to correct it? Newb here so details are appreciated. Thanks for your time in advance!
Code:
#!/usr/bin/python
import zipfile
from PySide import QtGui
import re
#Select file to extract
app = QtGui.QApplication([])
dialog = QtGui.QFileDialog()
dialog.setFileMode(QtGui.QFileDialog.AnyFile)
if (dialog.exec()):
fileName = dialog.selectedFiles()
#Select Directory to extract to
dialog = QtGui.QFileDialog()
dialog.setFileMode(QtGui.QFileDialog.Directory)
dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
if (dialog.exec()):
dirName = dialog.selectedFiles()
print("Extracting.....")
zFile= zipfile.ZipFile(fileName)
zFile.extractall(dirName)
Error output:
Traceback (most recent call last):
File "C:\Users\Jennifer\Documents\BatchScripts\unzip.py", line 22, in <module>
zFile= zipfile.ZipFile(fileName)
File "C:\Python33\lib\zipfile.py", line 933, in __init__
self._RealGetContents()
File "C:\Python33\lib\zipfile.py", line 970, in _RealGetContents
endrec = _EndRecData(fp)
File "C:\Python33\lib\zipfile.py", line 237, in _EndRecData
fpin.seek(0, 2)
AttributeError: 'list' object has no attribute 'seek'
In your file and target directory code blocks, dialog.selectedFiles() returns a list. zipfile.ZipFile can only handle one file at a time, hence your error. To iterate over the list being provided by dialog.selectedFiles(), use the following:
for archive in fileName: # you should probably change it to fileNames to reflect its true nature
zfile = zipfile.ZipFile(archive)
print("Extracting " + str(zfile.filename) + "...")
zfile.extractall(dirName[0]) # also a list, extract to first item and ignore rest
and you should be all set.