This error is not seen every time. When the application runs multiple times we have seen this issue.
Can one help me regarding this?
sql_query = 'SELECT * FROM hourly_table where mac=? and name=? and processedhour >= ? and processedhour < ? ;'
Traceback (most recent call last):
File "/opt/Extraction/main/CassandraOps.py", line 1229, in selectConcurrent
select_statement = session.prepare(sql_query)
File "cassandra/cluster.py", line 2496, in cassandra.cluster.Session.prepare (cassandra/cluster.c:43515)
raise
File "cassandra/cluster.py", line 2493, in cassandra.cluster.Session.prepare (cassandra/cluster.c:43365)
query_id, bind_metadata, pk_indexes, result_metadata, result_metadata_id = future.result()
File "cassandra/cluster.py", line 4198, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:80578)
raise self._final_exception
AttributeError: 'PrepareMessage' object has no attribute 'consistency_level'
Expected Query:
select called_station_id,unixtimestamp,acct_session_id,nas_port_id,session_mac,acct_input_octets,acct_output_octets from cdr_sessionterminated where called_station_id = '421888800011' and unixtimestamp>='2021-07-28 11:00:00Z'and unixtimestamp < '2021-07-28 12:00:00Z';
Code:
`
sql_query = "SELECT {} FROM {} where called_station_id = ? and unixtimestamp >= '{}Z' and unixtimestamp < '{}Z' ;".format(columns, table, timeUnitFrom, timeUnitTo)
select_statement = session.prepare(sql_query)
statements_and_params = []
for row in queryFrame.itertuples(index=False):
row = list(row)
params = ()
for column in range(0, len(columnList)):
params+=(row[column],)
statements_and_params.append((select_statement, params))
results = execute_concurrent(session, statements_and_params,raise_on_first_error=False, concurrency=10)
`
Error:
'PrepareMessage' object has no attribute 'consistency_level'
Note:
I'm not getting this error always. it's not even consistent for the past 24 hours I got this error twice.
This looks like a Python coding issue and not specific to Cassandra.
I would suggest that you review your code particularly where you are creating prepared statements and check for errors. For example, it's likely that sections of the code are not indented correctly leading to the error you posted. Cheers!
Related
I'm trying to plot the voltage/current coming out of a device, with these being written to a file and then displayed on the same plot, which updates in real time. Currently the code does this, but it pops up with an error message each time the graph updates which seems to be slowing the pace at which the program takes measurements.
The error seems to be occurring each time the graph updates i.e. when plt.draw() is executed within the While loop, making me think that it occurs in def animate_readings(i), though I've included all pertinent pieces of code just in case.
plt.ion()
...
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.clear()
ax2 = ax1.twinx()
ax2.clear()
plt.xlim(-7,3)
ax1.set_ylabel('Voltage V')
ax2.set_ylabel('Current mA')
ax1.set_ylim(-0.5,27)
ax2.set_ylim(-5, 400, 10)
Vpatch = mpatches.Patch(color='blue', label='Voltage')
Cpatch = mpatches.Patch(color='red', label='Current')
plt.legend(handles=[Vpatch, Cpatch])
plt.draw()
plt.pause(0.1)
"Is used to assign properties to the graph used in FuncAnimation"
def animate_readings(i):
plt.xlim(c-8,c+2)
ax1.plot(AVdata, color='b')
ax2.plot(ACdata, color='r')
Artists = namedtuple ('Artists', ('AVdata', 'ACdata'))
returnable = Artists(
ax1.plot(AVdata, color='b'),
ax2.plot(ACdata, color='r')
)
return returnable
...
while 1:
print 1
"Below if statement names and creates file at beginning of operation"
ani = animation.FuncAnimation(fig, animate_readings, interval=200, blit=True)
...
if c % 1 == 0:
print "2b"
try:
plt.draw()
plt.pause(0.1)
print "2c"
except :
pass
print 2
c = c + 1
The error which pops up after print "2b" executes is as follows. Nominally the loop should be running ~3x a second but, due to the error it only runs every 3 seconds and, in a recent extended test, only recorded readings every 30 seconds.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/matplotlib/cbook/__init__.py", line 388, in process
proxy(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/cbook/__init__.py", line 228, in __call__
return mtd(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 1026, in _start
self._init_draw()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 1750, in _init_draw
self._draw_frame(next(self.new_frame_seq()))
File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 1778, in _draw_frame
a.set_animated(self._blit)
AttributeError: 'list' object has no attribute 'set_animated'
I am new to HDF5 file format and I have a data(images) saved in HDF5 format. The images are saved undere a group called 'data' which is under the root group as Carrays. what I want to do is to retrive a slice of the saved images. for example the first 400 or somthing like that. The following is what I did.
h5f = h5py.File('images.h5f', 'r')
image_grp= h5f['/data/'] #the image group (data) is opened
print(image_grp[0:400])
but I am getting the following error
Traceback (most recent call last):
File "fgf.py", line 32, in <module>
print(image_grp[0:40])
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
(/feedstock_root/build_artefacts/h5py_1496410723014/work/h5py-2.7.0/h5py/_objects.c:2846)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
(/feedstock_root/build_artefacts/h5py_1496410723014/work/h5py
2.7.0/h5py/_objects.c:2804)
File "/..../python2.7/site-packages/h5py/_hl/group.py", line 169, in
__getitem__oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "/..../python2.7/site-packages/h5py/_hl/base.py", line 133, in _e name = name.encode('ascii')
AttributeError: 'slice' object has no attribute 'encode'
I am not sure why I am getting this error but I am not even sure if I can slice the images which are saved as individual datasets.
I know this is an old question, but it is the first hit when searching for 'slice' object has no attribute 'encode' and it has no solution.
The error happens because the "group" is a group which does not have the encoding attribute. You are looking for the dataset element.
You need to find/know the key for the item that contains the dataset.
One suggestion is to list all keys in the group, and then guess which one it is:
print(list(image_grp.keys()))
This will give you the keys in the group.
A common case is that the first element is the image, so you can do this:
image_grp= h5f['/data/']
image= image_grp(image_grp.keys[0])
print(image[0:400])
yesterday I had a similar error and wrote this little piece of code to take my desired slice of h5py file.
import h5py
def h5py_slice(h5py_file, begin_index, end_index):
slice_list = []
with h5py.File(h5py_file, 'r') as f:
for i in range(begin_index, end_index):
slice_list.append(f[str(i)][...])
return slice_list
and it can be used like
the_desired_slice_list = h5py_slice('images.h5f', 0, 400)
Running the below script works for 60% of the entries from the MasterGroupList however suddenly fails with the below error. although my questions seem to be poor ou guys have been able to help me before. Any idea how I can avoid getting this error? or what is trhoughing off the script? The masterGroupList looks like:
Groups Pulled from AD
SET00 POWERUSER
SET00 USERS
SEF00 CREATORS
SEF00 USERS
...another 300 entries...
Error:
Traceback (most recent call last):
File "C:\Users\ks185278\OneDrive - NCR Corporation\Active Directory Access Scr
ipt\test.py", line 44, in <module>
print group.member
File "C:\Python27\lib\site-packages\active_directory.py", line 805, in __getat
tr__
raise AttributeError
AttributeError
Code:
from active_directory import *
import os
file = open("C:\Users\NAME\Active Directory Access Script\MasterGroupList.txt", "r")
fileAsList = file.readlines()
indexOfTitle = fileAsList.index("Groups Pulled from AD\n")
i = indexOfTitle + 1
while i <= len(fileAsList):
fileLocation = 'C:\\AD Access\\%s\\%s.txt' % (fileAsList[i][:5], fileAsList[i][:fileAsList[i].find("\n")])
#Creates the dir if it does not exist already
if not os.path.isdir(os.path.dirname(fileLocation)):
os.makedirs(os.path.dirname(fileLocation))
fileGroup = open(fileLocation, "w+")
#writes group members to the open file
group = find_group(fileAsList[i][:fileAsList[i].find("\n")])
print group.member
for group_member in group.member: #this is line 44
fileGroup.write(group_member.cn + "\n")
fileGroup.close()
i+=1
Disclaimer: I don't know python, but I know Active Directory fairly well.
If it's failing on this:
for group_member in group.member:
It could possibly mean that the group has no members.
Depending on how phython handles this, it could also mean that the group has only one member and group.member is a plain string rather than an array.
What does print group.member show?
The source code of active_directory.py is here: https://github.com/tjguk/active_directory/blob/master/active_directory.py
These are the relevant lines:
if name not in self._delegate_map:
try:
attr = getattr(self.com_object, name)
except AttributeError:
try:
attr = self.com_object.Get(name)
except:
raise AttributeError
So it looks like it just can't find the attribute you're looking up, which in this case looks like the 'member' attribute.
I'm working on an app that will stream events into BQ. Since Streamed Inserts require the table to pre-exist, I'm running the following code to check if the table exists, and then to create it if it doesn't:
TABLE_ID = "data" + single_date.strftime("%Y%m%d")
exists = False;
request = bigquery.tables().list(projectId=PROJECT_ID,
datasetId=DATASET_ID)
response = request.execute()
while response is not None:
for t in response.get('tables', []):
if t['tableReference']['tableId'] == TABLE_ID:
exists = True
break
request = bigquery.tables().list_next(request, response)
if request is None:
break
if not exists:
print("Creating Table " + TABLE_ID)
dataset_ref = {'datasetId': DATASET_ID,
'projectId': PROJECT_ID}
table_ref = {'tableId': TABLE_ID,
'datasetId': DATASET_ID,
'projectId': PROJECT_ID}
schema_ref = SCHEMA
table = {'tableReference': table_ref,
'schema': schema_ref}
table = bigquery.tables().insert(body=table, **dataset_ref).execute(http)
I'm running python 2.7, and have installed the google client API through PIP.
When I try to run the script, I get the following error:
No handlers could be found for logger "oauth2client.util"
Traceback (most recent call last):
File "do_hourly.py", line 158, in <module>
main()
File "do_hourly.py", line 101, in main
body=table, **dataset_ref).execute(http)
File "build/bdist.linux-x86_64/egg/oauth2client/util.py", line 142, in positional_wrapper
File "/usr/lib/python2.7/site-packages/googleapiclient/http.py", line 721, in execute
resp, content = http.request(str(self.uri), method=str(self.method),
AttributeError: 'module' object has no attribute 'request'
I tried researching the issue, but all I could find was info about confusing between urllib, urllib2 and Python 2.7 / 3.
I'm not quite sure how to continue with this, and will appreciate all help.
Thanks!
Figured out that the issue was in the following line, which I took from another SO thread:
table = bigquery.tables().insert(body=table, **dataset_ref).execute(http)
Once I removed the "http" variable, which doesn't exist in my scope, the exception dissappeared
What I'm trying to achieve here is to submit multiple jobs to Gearman and print the results returned by the workers once they are done with processing the job.
I've read through the examples on:
https://pythonhosted.org/gearman/1to2.html#client-multiple-tasks
https://pythonhosted.org/gearman/client.html
I then tried to implement the check_request_status in the following way:
list_of_jobs = []
for i in xrange(1,4,1):
list_of_jobs.extend(dict(task='run_task', data=str(i)))
completed_requests = gm_client.wait_until_jobs_completed(submitted_requests,
poll_timeout=30.0)
for job_request in completed_requests:
if job_request.complete:
print job_request.result
elif job_request.timed_out:
print "Job %s timed out!" % job_request.unique
elif job_request.state == JOB_UNKNOWN:
print "Job %s connection failed!" % job_request.unique
I'm getting the following error which I can't seem to figure out even after much Google-fu, searching through the Gearman Google Groups and poring through other people's implementation of Gearman:
Traceback (most recent call last):
File "supervisor.py", line 16, in <module>
completed_requests = gm_client.submit_multiple_jobs(list_of_jobs)
File "/usr/local/lib/python2.7/dist-packages/gearman/client.py", line 48, in submit_multiple_jobs
requests_to_submit = [self._create_request_from_dictionary(job_info, background=background, max_retries=max_retries) for job_info in jobs_to_submit]
File "/usr/local/lib/python2.7/dist-packages/gearman/client.py", line 169, in _create_request_from_dictionary
job_unique = job_info.get('unique')
AttributeError: 'str' object has no attribute 'get'
Does anyone know what's going on here?
Turns out the error is a simple one. In the for-loop above, simply use the append function instead of extend for adding a dict to the list_of_jobs array:
list_of_jobs.append(dict(task='run_task', data=str(i)))