I have seen all previous questions about this, but nothing seems to be working on my end. I am trying to run a test that uses a protobuf generated file, called 'resource_pb2'. I am using Python 3.8 with grpc 1.33.2 and protobuf version 3.14.
When using a class from this protobuf generated file, my test fails with the following error:
Parameter to MergeFrom() must be instance of same class: expected RecognitionResource got RecognitionResource
I've checked the type and id's of all the "recognition resource" classes being called in that particular test, and I get the following:
<class 'resource_pb2.RecognitionResource'> 2069160783760
<class 'resource_pb2.RecognitionResource'> 2069160783760
<class 'resource_pb2.RecognitionResource'> 2069160783760
They are clearly all being called from the same source, so why is this issue occuring?
I had a similar issue and the reason was that I had made a mistake when passing parameters to the function.
The problem was solved when I realized about my bug and I invoked the function in the right way, with all required parameters properly set.
Hope it helps.
Related
I am trying to use Python to run an external program using its COM interface. In general, everything works as expected. The only problem I’m having is that any time I try to retrieve a value from the program using their GetValue method, I get the following error (code included).
This method is supposed to overwrite the value of my Value variable. The function takes 3 arguments, and I have verified that the error is related to the first argument (Value) by using separate functions successfully that only take the last 2 arguments. The documentation for the COM interface mentions this issue for C#, and their recommended solution was to define Value as an Object type variable and set the value to null. I have it set to None below, but I’ve also tried setting it to different int/float/string with no success.
I receive this error whether or not I use the EnsureModule command before dispatch.
See the code below
Object = win32.Dispatch(“COMObject”)
Object.OpenFile(“Filename”)
Value = None
Object.GetValue(Value,0,1)
Exception has occurred:com_error
(-2147352571,’type mismatch’,None,1)
I'm porting a Python GTK application from python2 to python3, using version 3.5.2. As part of this, I'm switching to updated GTK API calls. I need to call the gtk.TextBuffer constructor, described [here][1]. Following that documentation, I wrote:
tb = gtk.TextBuffer(table=text_tag_table)
This gives the following error:
*** TypeError: gobject `GtkTextBuffer' doesn't support property 'table'
I tried removing the table= part of the call:
gtk.TextBuffer(table=text_tag_table)
This gives:
*** TypeError: GObject.__init__() takes exactly 0 arguments (1 given)
I can call the constructor without arguments, e.g., tb = gtk.TextBuffer(). I tried setting the tag table manually, like this:
tb.set_property("tag-table", text_tag_table)
This gives a warning:
__main__:1: Warning: g_object_set_property: construct property "tag-table" for object 'GtkTextBuffer' can't be set after construction
It seems like the original constructor with the table= arg should work. Can anyone help me figure out why it throws a TypeError? I did confirm using pydb that text_tag_table is an object of the correct type:
(Pdb) p text_tag_table
<Gtk.TextTagTable object at 0x7fb723d6b288 (GtkTextTagTable at 0x2b2e8e0)>
Thanks very much in advance!
The fix for this was to use the new method:
tb = gtk.TextBuffer.new(table=text_tag_table)
I'm a bit surprised that this works, but it seems fine!
I'm currently looking into myHdl to see if it's worth using or not. However, I've come across a hiccup regarding the instantiation of modules. I've got two files, one that's a module and one that's the testbench. Inside the testbench, I've instantiated the module following the example they have on the website:
http://www.myhdl.org/examples/flipflops.html
The instantiation specifically is this line: dff_inst = dff(q, d, clk)
However, I get an error when I try to run the testbench:
Exception TypeError: 'isinstance() arg 2 must be a class, type, or tuple of classes and types' in <generator object _LabelGenerator at 0x7f6070b2ea50> ignored
I assume this has something to do with the fact that I have two separate files, so my guess is that python isn't finding the dff module(since it's in a separate file). I tried adding in an import dff line, but that simply gave me a 'module' object is not callable type error, which makes sense.
Looking in the documentation, they don't have a full .py file, so I'm not sure how they're linking these testbenches with the module. They specifically mention a hierarchy system and being able to instantiate other modules, but I can't seem to get it to work.
From what I understand from documentation, it looks like they're just writing the testbench and the module in the same file. However, to my understanding, it looks like they imply you can import modules, but I can't figure out how that's done. Is there just some simple thing I'm overlooking?
After experimenting a bit, it seems like I just need to use the following command: from dff import dff,
which makes a lot of sense.
I see there is a way for me page the results in python and I found the following example code:
https://bitbucket.org/jaraco/python-ldap/src/f208b6338a28/Demo/paged_search_ext_s.py
When I copy this code and try to modify it to what I need it to do when running the code I get a "TypeError: init() got an unexpected keyword argument 'cookie'"
I even reverted the code back to its default and get the same error. If someone could point me in the correct direction it would be much appreciated.
Thanks
Update your python-ldap module:
pip install python-ldap --upgrade
That class changed from this commit and mentioned:
new class API in ldap.controls, not backwards-compatible!
The problem is on this line:
req_ctrl = SimplePagedResultsControl(True,size=self.page_size,cookie='')
Find where that SimplePagedResultsControl class is defined and examine the parameter list for its constructor to get the correct constructor parameter list.
EDIT:
Looks like the constructor signature has been changed. Either upgrade as Omid Raha recommends or try the old method signature below if you are unable to upgrade for some reason.
paged_results_control = SimplePagedResultsControl(ldap.LDAP_CONTROL_PAGE_OID, True, (self.page_size, ''))
I've started to learn python in the past few days, and while exploring object-oriented programming I'm running into problems.
I'm using Eclipse while running the pydev plugin, am running on the python 3.3 beta, and am using a windows 64 bit system.
I can initialize a class fine and use any methods within it, as long as I'm not trying to extend the superclass (each class I've coded in a different source file)
For example, the following code compiles and runs fine.
class pythonSuper:
string1 = "hello"
def printS():
print pythonSuper.string1
and the code to access and run it...
from stackoverflow.questions import pythonSuper
class pythonSub:
pysuper = pythonSuper.pythonSuper()
pysuper.printS()
Like I said, that works. The following code doesn't
class pythonSuper: """Same superclass as above. unmodified, except for the spacing"""
string1 = "hello"
def printS(self):
print(pythonSuper.string1)
Well, that's not quite true. The superclass is absolutely fine, at least to my knowledge. It's the subclass that weirds out
from stackoverflow.questions import pythonSuper
class pythonSub(pythonSuper):
pass
pythonObject = pythonSub()
pythonSub.pythonSuper.printS()
when the subclass is run Eclipse prints out this error
Traceback (most recent call last):
File "C:\Users\Anish\workspace\Python 3.3\stackoverflow\questions\pythonSub.py",
line 7, in <module>
class pythonSub(pythonSuper):
TypeError: module.__init__() takes at most 2 arguments (3 given)
I have no idea what's going on. I've been learning python from thenewboston's tutorials, but those are outdated (I think his tutorial code uses python version 2.7). He also codes in IDLE, which means that his classes are all contained in one file. Mine, however, are all coded in files of their own. That means I have no idea whether the code errors I'm getting are the result of outdated syntax or my lack of knowledge on this language. But I digress. If anyone could post back with a solution and/or explanation of why the code is going wrong and what I could do to fix it. An explanation would be preferred. I'd rather know what I'm doing wrong so I can avoid and fix the problem in similar situations than just copy and paste some code and see that it works.
Thanks, and I look forward to your answers
I ran your code, albeit with a few modifications and it runs perfectly. Here is my code:
pythonSuper:
class pythonSuper:
string1 = 'hello'
def printS(self):
print(self.string1)
main:
from pythonSuper import pythonSuper as pySuper
class pythonSub(pySuper):
pass
pythonObject = pythonSub()
pythonObject.printS()
NOTE: The change I have made to your code is the following:
In your code, you have written pythonSub.pythonSuper.printS() which is not correct, because via pythonSub you already support a printS() method, directly inherited from the superclass. So there is no need to refer to the superclass explicitly in that statement. The statement that I used to substitute the aforementioned one, pythonObject.printS(), seems to have addressed this issue.
pythonSuper refers to the module, not the class.
class pythonSub(pythonSuper.pythonSuper):
pass