I'm trying to connect to biometric device. I have installed 'Zklib' using (Pip). My code as follows
`import sys
import zklib
import time
from zklib import zkconst
zk = zklib.ZKLib("192.168.0.188", 4370)
ret = zk.connect()
print "connection:", ret`
When I execute this, I get an error
AttributeError: 'module' object has no attribute 'ZKLib'
Help me to run this code successfully.
Try the following instead:
import sys
import time
from zklib import zklib, zkconst
zk = zklib.ZKLib("192.168.0.188", 4370)
ret = zk.connect()
print "connection:", ret
The ZKlib class is in zklib.zklib not zklib. It appears that there is a typo in the Getting Started section of their GitHub page (or they expect you to be in the zklib directory when running your code?).
Related
I keep trying to run a bit of python on mac terminal, and I'm hit with the following error: "TypeError: 'module' object is not callable"
Reference code:
import re
import pathlib as Path
mypath = Path('users/pranav/Desktop/sir/samplenames.txt')
Could someone break down the error for me and explain what I should do to fix it?
I also tried to fix it using sys, however, before I could even work through it I was returned an error stating: AttributeError: 'list' object has no attribute 'dirname'
Code w/ sys:
import sys
print(sys.path.dirname())
import re
import pathlib as Path
mypath = Path('/users/pranav/Desktop/sir/samplenames.txt')
Any help would be greatly appreciated
from pathlib import Path
SCR_DIR = 'C:\\users\\pranav\\Desktop\\sir'
mypath = Path(SRC_DIR, "samplenames.txt")
I have below code getting trying to dump table data but below error TypeError: 'int' object is not iterable.
import argparse
import sys
import itertools
import codecs
import uuid
import os
try:
import cassandra
import cassandra.concurrent
except ImportError:
sys.exit('Python Cassandra driver not installed. You might try \"pip install cassandra-driver\".')
from cassandra.cluster import Cluster, ResultSet
from cassandra.policies import DCAwareRoundRobinPolicy
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import ConsistencyLevel
datafile = "/Users/username/adf.csv"
if os.path.exists(datafile):
os.remove(datafile)
def dumptableascsv():
auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra')
cluster = Cluster(['127.0.0.1'],
load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='Cassandra'),
port=9042, auth_provider=auth_provider)
session = cluster.connect('qualys_ioc')
session.execute("COPY qualys_ioc.agent_delta_fragment(agent_id , delta_id , fragment_id, boolean ,created_on) TO "
"'/Users/username/adf.csv' WITH HEADER = true ;", ConsistencyLevel.QUORUM)
dumptableascsv()
COPY is a cqlsh commend -- it is not part of CQL, and cannot be executed via native protocol clients. You are getting this particular error instead of a server request error because you're passing a consistency level in the parameters position of Session.execute.
You can use cqlsh to do this from a script, or have a look at the DS Bulk tool for high performance loading and unloading.
What I want to do:
I want to import a python module (pocketsphinx) and use the output from the Decoder attribute. However when I try to use it, I'm informed that module attribute 'Decoder' doesn't exist.
decoder = Decoder(configSwitches)
It does exist, though, which is what makes it so strange.
What I've done so far:
When I pull up a python console and input import pocketsphinx, it imports without any issue. Running pocketsphinx.file returns:
'/usr/local/lib/python2.7/dist-packages/pocketsphinx-0.0.8-py2.7-linux-armv7l.egg/pocketsphinx/__init__.pyc'
Looking in '/usr/local/lib/python2.7/dist-packages/pocketsphinx-0.0.8-py2.7-linux-armv7l.egg/pocketsphinx/__init__.py', I see: from pocketsphinx import * and that's it.
When I go back up to /usr/local/lib/python2.7/dist-packages/pocketsphinx/pocketsphinx.py and open it in a text editor, I see that pocketsphinx.py does indeed have a Decoder class with a healthy number of defined methods.
My Ask:
What other steps can I take to diagnose what's wrong with my use of the pocketsphinx module?
Here's the example code I was trying to run before really digging into the project:
import pocketsphinx
hmmd = r"/home/michael/Desktop/sphinxASR/pocketsphinx-5prealpha/model/en-us/en-us"
lmdir = r"/home/michael/Desktop/sphinxASR/pocketsphinx-5prealpha/model/en-us/en-us.lm.bin"
dictp = r"/home/michael/Desktop/sphinxASR/pocketsphinx-5prealpha/model/en-us/cmudict-en-us.dict"
fileName = r'/home/michael/Desktop/sphinxASR/voice_message.wav'
if __name__ == "__main__":
wavFile = open(fileName, "rb")
speechRec = pocketsphinx.Decoder(hmm=hmmd, lm=lmdir, dictionary=dictp)
wavFile.seek(44)
speechRec.decode_raw(wavFile)
result = speechRec.get_hyp()
print(result)
Stack trace:
Traceback (most recent call last):
File "/home/michael/PycharmProjects/27test/getHypTest.py", line 14, in <module>
speechRec = pocketsphinx.Decoder(lm=lmdir, dictionary=dictp)
AttributeError: 'module' object has no attribute 'Decoder'
By looking at the pocketsphinx example code, it seems that your import should be:
from pocketsphinx.pocketsphinx import *
My first step diagnosing this issue would be to type the following, so that I can see what is being imported:
import pocketsphinx
dir(pocketsphinx)
You should import Decoder from pocketsphinx.
Instead of
import pocketsphinx
try:
from pocketsphinx.pocketsphinx import Decoder
I'm trying to remote into an interactive shell and import modules within python 2.7. I'm getting hung up. So far this is what I've got:
import rpyc
import socket
hostname = socket.gethostname()
port = 12345
connections = rpyc.connect(hostname,port)
session = connections.root.getSession()
session exists
>>>session
<blah object at 0xMore-Goop>
I want to issue an import sys so I can add another module to the path. However when I try to see if modules exist in the path I get the following:
>>>connections.modules
AttributeError: 'Connection' object has no attribute 'modules'
What I need to execute remotely is the following:
import sys
sys.path.append(path/to/import)
import file
log = file.logger(session, path/to/log)
Is it possible to have rpyc issue the above content? Thanks in advance
You can add the following methods to the service:
import sys, importlib, rpyc
...
class MyService(rpyc.Service):
...
def exposed_import_module(self, mod):
return importlib.import_module(mod)
def exposed_add_to_syspath(self, path):
return sys.path.append(path)
and access it like this:
connections.root.add_to_syspath('path/to/import')
file = connections.root.import_module('file')
file.logger(session, 'path/to/log')
I am trying to run following python code from c++(embedding python).
import sys
import os
import time
import win32com.client
from com.dtmilano.android.viewclient import ViewClient
import re
import pythoncom
import thread
os.popen('adb devices')
CANalyzer = None
measurement = None
def can_start(config_path):
global CANalyzer,measurement
CANalyzer = win32com.client.Dispatch('CANalyzer.Application')
CANalyzer.Visible = 1
measurement = CANalyzer.Measurement
CANalyzer.Open(config_path)
measurement.Start()
com_marshall_stream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,CANalyzer)
return com_marshall_stream
When i try to call can_start function, i am getting python type error . Error traceback is mentioned below.
"type 'exceptions.TypeError'. an integer is required. traceback object at 0x039A198"
The function is executing if i directly ran it from the python and also it is executing in my pc, where the code was developed. But later when i transferred to another laptop, i am experiencing this problem.