JPype and JayDeBeAPI: AttributeError: 'property' object has no attribute 'isBeanAccessor' - python

I have built JPype (JPype1-0.5.5.4) along with JayDeBeAPI 0.1.4 in my attempt to connect to a database via JDBC. This is on RHEL. I can successfully connect using the driver,
TrgtCnn = jaydebeapi.connect('com.ibm.as400.access.AS400JDBCDriver',
['jdbc:as400://<mask>','<mask>','<mask>'],
'/app/as/lib/jdbc/jt400.jar')
but I get this traceback in JPype when I execute SQL:
TrgtCrs = TrgtCnn.cursor()
TrgtCrs.execute("SELECT * FROM WA6U999S")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-5d46ea8c382d> in <module>()
----> 1 TrgtCrs.execute("SELECT * FROM WA6U999S")
/app/as/opt/anaconda/lib/python2.7/site-packages/jaydebeapi/dbapi2.pyc in execute(self, operation, parameters)
356 parameters = ()
357 self._close_last()
--> 358 self._prep = self._connection.jconn.prepareStatement(operation)
359 self._set_stmt_parms(self._prep, parameters)
360 is_rs = self._prep.execute()
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in _getClassFor(javaClass)
66 return _CLASSES[name]
67
---> 68 pyJavaClass = _JavaClass(javaClass)
69 _CLASSES[name] = pyJavaClass
70 return pyJavaClass
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in __new__(mcs, jc)
123 elif not jc.isInterface():
124 bjc = jc.getBaseClass(jc)
--> 125 bases.append(_getClassFor(bjc))
126
127 if _JAVATHROWABLE is not None and jc.isSubclass("java.lang.Throwable"):
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in _getClassFor(javaClass)
66 return _CLASSES[name]
67
---> 68 pyJavaClass = _JavaClass(javaClass)
69 _CLASSES[name] = pyJavaClass
70 return pyJavaClass
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in __new__(mcs, jc)
166 for i in _CUSTOMIZERS:
167 if i.canCustomize(name, jc):
--> 168 i.customize(name, jc, bases, members)
169
170 # remove multiple bases that would cause a MRO problem
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_properties.pyc in customize(self, class_name, jc, bases, members)
68
69 def customize(self, class_name, jc, bases, members) :
---> 70 accessor_pairs = _extract_accessor_pairs(members)
71 for attr_name, (getter, setter) in accessor_pairs.items():
72 if attr_name in members:
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_properties.pyc in _extract_accessor_pairs(members)
46 if _is_java_method(members[property_name]):
47 continue
---> 48 if access == 'get' and member.isBeanAccessor():
49 try:
50 pair = accessor_pairs[property_name]
AttributeError: 'property' object has no attribute 'isBeanAccessor'
I have no idea where to start on this and can't seem to find anything mentioning anything close to this issue.

This appears to be a bug in JPype.
I don't have access to an AS/400 database, but I do have an Oracle XE database lying around and I was able to use that to reproduce the problem. The Python code I used was as follows:
#!/usr/bin/python
import jaydebeapi
conn = jaydebeapi.connect('oracle.jdbc.OracleDriver', ['jdbc:oracle:thin:#localhost:1521:XE', 'user', 'password'])
print conn
I found what I believe to be a fix for the problem, which I have posted to the JPype issue above. This fix was to edit the function _extract_accessor_pairs in jpype/_properties.py, find the following code and replace the or with an and:
for name, member in members.items():
if not (len(name) > _PROPERTY_ACCESSOR_PREFIX_LEN \
or _is_java_method(member)):
continue
# rest of loop omitted...
After making this change, the error I was getting went away. You're welcome to try this fix and see if it works for you too.

Related

create_collection() got an unexpected keyword argument 'embedding_fn'

I was trying to use the langchain library to create a question answering system. But when I try to search in the document using the chromadb library it gives this error:
TypeError: create_collection() got an unexpected keyword argument 'embedding_fn'
Here's the code am working on
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.document_loaders import TextLoader
from langchain.vectorstores import Chroma
loader = TextLoader('./info.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_documents(texts, embeddings).
The last line generates the error.
This is the complete error message:
TypeError Traceback (most recent call last)
Input In [36], in <cell line: 1>()
----> 1 docsearch = Chroma.from_documents(texts, embeddings)
File ~\anaconda3\lib\site-packages\langchain\vectorstores\chroma.py:212, in Chroma.from_documents(cls, documents, embedding, ids, collection_name, persist_directory, **kwargs)
210 texts = [doc.page_content for doc in documents]
211 metadatas = [doc.metadata for doc in documents]
--> 212 return cls.from_texts(
213 texts=texts,
214 embedding=embedding,
215 metadatas=metadatas,
216 ids=ids,
217 collection_name=collection_name,
218 persist_directory=persist_directory,
219 )
File ~\anaconda3\lib\site-packages\langchain\vectorstores\chroma.py:178, in Chroma.from_texts(cls, texts, embedding, metadatas, ids, collection_name, persist_directory, **kwargs)
151 #classmethod
152 def from_texts(
153 cls,
(...)
160 **kwargs: Any,
161 ) -> Chroma:
162 """Create a Chroma vectorstore from a raw documents.
163
164 If a persist_directory is specified, the collection will be persisted there.
(...)
176 Chroma: Chroma vectorstore.
177 """
--> 178 chroma_collection = cls(
179 collection_name=collection_name,
180 embedding_function=embedding,
181 persist_directory=persist_directory,
182 )
183 chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)
184 return chroma_collection
File ~\anaconda3\lib\site-packages\langchain\vectorstores\chroma.py:65, in Chroma.__init__(self, collection_name, embedding_function, persist_directory)
60 logger.warning(
61 f"Collection {collection_name} already exists,"
62 " Do you have the right embedding function?"
63 )
64 else:
---> 65 self._collection = self._client.create_collection(
66 name=collection_name,
67 embedding_fn=self._embedding_function.embed_documents
68 if self._embedding_function is not None
69 else None,
70 )
TypeError: create_collection() got an unexpected keyword argument 'embedding_fn'
The create_collection method of chromadb.Client was changed 2 days ago and the embedding_fn parameter was renamed to embedding_function:
https://github.com/chroma-core/chroma/commit/6ce2388e219d47048e854be72be54617df647224
The source code for the langchain.vectorstores.chroma.Chroma class as of version 0.0.87 seems to have been updated already (3 hours before you asked the question) to match the chromadb library:
https://github.com/hwchase17/langchain/commit/34cba2da3264ccc9100f7efd16807c8d2a51734c
So you should be able to fix the problem by installing the newest version of LangChain.

Altair: NoMatchingVersions when saving maps with selenium

I am trying to create a series and save them iteratively.
The creation works well but while saving I get the following error:
---------------------------------------------------------------------------
NoMatchingVersions Traceback (most recent call last)
<ipython-input-103-e75c3f4b4fa5> in <module>
29 chart=(background + chart).configure_view(stroke='white')
30 filename = f"{scenario}.svg"
---> 31 save(chart, filename, method='selenium', webdriver=driver)
~\Anaconda3\lib\site-packages\altair_saver\_core.py in save(chart, fp, fmt, mode, method, **kwargs)
75 saver = Saver(spec, mode=mode, **kwargs)
76
---> 77 saver.save(fp=fp, fmt=fmt)
78
79
~\Anaconda3\lib\site-packages\altair_saver\savers\_saver.py in save(self, fp, fmt)
86 raise ValueError(f"Got fmt={fmt}; expected one of {self.valid_formats}")
87
---> 88 content = self.mimebundle(fmt).popitem()[1]
89 if isinstance(content, dict):
90 with maybe_open(fp, "w") as f:
~\Anaconda3\lib\site-packages\altair_saver\savers\_saver.py in mimebundle(self, fmts)
66 f"invalid fmt={fmt!r}; must be one of {self.valid_formats}."
67 )
---> 68 bundle.update(self._mimebundle(fmt))
69 return bundle
70
~\Anaconda3\lib\site-packages\altair_saver\savers\_selenium.py in _mimebundle(self, fmt)
249
250 def _mimebundle(self, fmt: str) -> Mimebundle:
--> 251 out = self._extract(fmt)
252 mimetype = fmt_to_mimetype(
253 fmt,
~\Anaconda3\lib\site-packages\altair_saver\savers\_selenium.py in _extract(self, fmt)
209 js_resources = {
210 "vega.js": get_bundled_script("vega", self._vega_version),
--> 211 "vega-lite.js": get_bundled_script("vega-lite", self._vegalite_version),
212 "vega-embed.js": get_bundled_script(
213 "vega-embed", self._vegaembed_version
~\Anaconda3\lib\site-packages\altair_viewer\_scripts.py in get_bundled_script(package, version)
36 f"package {package!r} not recognized. Available: {list(listing)}"
37 )
---> 38 version_str = find_version(version, listing[package])
39 content = pkgutil.get_data("altair_viewer", f"scripts/{package}-{version_str}.js")
40 if content is None:
~\Anaconda3\lib\site-packages\altair_viewer\_utils.py in find_version(version, candidates, strict_micro)
190 if not matches:
191 raise NoMatchingVersions(
--> 192 f"No matches for version={version!r} among {candidates}"
193 )
194 return str(matches[-1])
NoMatchingVersions: No matches for version='4.8.1' among ['4.0.2']
I am using selenium and altair_saver:
from altair_saver import save
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'pathtochromedriver/chromedriver_win32/chromedriver.exe')
for i, scenario in enumerate(scenario_columns):
chart=makechart(scenario, i)
filename = f"{scenario}.svg"
save(chart, filename, method='selenium', webdriver=driver)
Here `scenario` is a string without special characters.
You need to update the altair_viewer package to a newer version:
$ pip install -U altair_viewer
(This error was improved in https://github.com/altair-viz/altair_viewer/pull/33, so shouldn't be as mysterious when it comes up in the future).

what is the problem ?: application.connect() error

I am a beginner developer who started to study automation by using pywinauto.
An overflow error occurs when using application.connect () to connect to an already open program.
But application.start() works fine....
Please help me if someone know this part.
The source code and error contents are as follows.
Source code:
import pywinauto
app = pywinauto.application.Application()
app.connect(title_re='Calculator')
Error:
OverflowError Traceback (most recent call last)
in
1 import pywinauto
2 app = pywinauto.application.Application()
----> 3 app.connect(title_re='Calculator')
d:\Anaconda3\lib\site-packages\pywinauto\application.py in connect(self, **kwargs)
972 ).process_id
973 else:
--> 974 self.process = findwindows.find_element(**kwargs).process_id
975 connected = True
976
d:\Anaconda3\lib\site-packages\pywinauto\findwindows.py in find_element(**kwargs)
82 so please see :py:func:find_elements for the full parameters description.
83 """
---> 84 elements = find_elements(**kwargs)
85
86 if not elements:
d:\Anaconda3\lib\site-packages\pywinauto\findwindows.py in find_elements(class_name, class_name_re, parent, process, title, title_re, top_level_only, visible_only, enabled_only, best_match, handle, ctrl_index, found_index, predicate_func, active_only, control_id, control_type, auto_id, framework_id, backend, depth)
279 return title_regex.match(t)
280 return False
--> 281 elements = [elem for elem in elements if _title_match(elem)]
282
283 if visible_only:
d:\Anaconda3\lib\site-packages\pywinauto\findwindows.py in (.0)
279 return title_regex.match(t)
280 return False
--> 281 elements = [elem for elem in elements if _title_match(elem)]
282
283 if visible_only:
d:\Anaconda3\lib\site-packages\pywinauto\findwindows.py in _title_match(w)
275 def _title_match(w):
276 """Match a window title to the regexp"""
--> 277 t = w.rich_text
278 if t is not None:
279 return title_regex.match(t)
d:\Anaconda3\lib\site-packages\pywinauto\win32_element_info.py in rich_text(self)
81 def rich_text(self):
82 """Return the text of the window"""
---> 83 return handleprops.text(self.handle)
84
85 name = rich_text
d:\Anaconda3\lib\site-packages\pywinauto\handleprops.py in text(handle)
86 length += 1
87
---> 88 buffer_ = ctypes.create_unicode_buffer(length)
89
90 ret = win32functions.SendMessage(
d:\Anaconda3\lib\ctypes_init_.py in create_unicode_buffer(init, size)
286 return buf
287 elif isinstance(init, int):
--> 288 buftype = c_wchar * init
289 buf = buftype()
290 return buf
OverflowError: cannot fit 'int' into an index-sized integer
import pywinauto
app = pywinauto.Application(backend='uia').start('calc.exe')
try this if you are having problem you have to say the backennd is a uia it working fine for me.

Type error making a betfair.py API call

I've just been moving some code over to a Ubuntu 16.04.2 anaconda setup, and am getting a type error I don't understand when calling code which works fine across numerous other machines.
The error replicates for me just off of the list all tennis markets sample code in the repo below, as well as a request like:
from betfair import Betfair
client = Betfair("app key needed here", "path to ssh key here")
client.login(username, password)
client.keep_alive()
client.list_market_book(market_ids=['1.135391020'], price_projection=dict(priceData=['EX_BEST_OFFERS']))
or
from betfair.models import MarketFilter
event_types = client.list_event_types(
MarketFilter(text_query='tennis')
)
print(len(event_types)) # 2
print(event_types[0].event_type.name) # 'Tennis'
tennis_event_type = event_types[0]
markets = client.list_market_catalogue(
MarketFilter(event_type_ids=[tennis_event_type.event_type.id])
)
markets[0].market_name
Both throw the following type error despite identical code working on a windows installation:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-69b51cf78438> in <module>()
1 event_types = client.list_event_types(
----> 2 MarketFilter(text_query='tennis')
3 )
4 print(len(event_types)) # 2
5 print(event_types[0].event_type.name) # 'Tennis'
<decorator-gen-125> in list_event_types(self, filter, locale)
/home/user/anaconda2/lib/python2.7/site-packages/betfair/utils.pyc in requires_login(func, *args, **kwargs)
121 self = args[0]
122 if self.session_token:
--> 123 return func(*args, **kwargs)
124 raise exceptions.NotLoggedIn()
/home/user/anaconda2/lib/python2.7/site-packages/betfair/betfair.pyc in list_event_types(self, filter, locale)
148 'listEventTypes',
149 utils.get_kwargs(locals()),
--> 150 model=models.EventTypeResult,
151 )
152
/home/user/anaconda2/lib/python2.7/site-packages/betfair/betfair.pyc in make_api_request(self, base, method, params, codes, model)
87 utils.check_status_code(response, codes=codes)
88 result = utils.result_or_error(response)
---> 89 return utils.process_result(result, model)
90
91 # Authentication methods
/home/user/anaconda2/lib/python2.7/site-packages/betfair/utils.pyc in process_result(result, model)
81 return result
82 if isinstance(result, collections.Sequence):
---> 83 return [model(**item) for item in result]
84 return model(**result)
85
/home/user/anaconda2/lib/python2.7/site-packages/betfair/meta/models.pyc in __init__(self, **data)
24 def __init__(self, **data):
25 super(BetfairModel, self).__init__()
---> 26 self.import_data(data)
27
28 def import_data(self, data, **kwargs):
/home/user/anaconda2/lib/python2.7/site-packages/betfair/meta/models.pyc in import_data(self, data, **kwargs)
28 def import_data(self, data, **kwargs):
29 kwargs['strict'] = False
---> 30 return super(BetfairModel, self).import_data(data, **kwargs)
/home/user/anaconda2/lib/python2.7/site-packages/schematics/models.pyc in import_data(self, raw_data, recursive, **kwargs)
269 The data to be imported.
270 """
--> 271 data = self._convert(raw_data, trusted_data=_dict(self), recursive=recursive, **kwargs)
272 self._data.converted.update(data)
273 if kwargs.get('validate'):
/home/user/anaconda2/lib/python2.7/site-packages/schematics/models.pyc in _convert(self, raw_data, context, **kwargs)
293 should_validate = getattr(context, 'validate', kwargs.get('validate', False))
294 func = validate if should_validate else convert
--> 295 return func(self._schema, self, raw_data=raw_data, oo=True, context=context, **kwargs)
296
297 def export(self, field_converter=None, role=None, app_data=None, **kwargs):
/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in convert(cls, mutable, raw_data, **kwargs)
427
428 def convert(cls, mutable, raw_data=None, **kwargs):
--> 429 return import_loop(cls, mutable, raw_data, import_converter, **kwargs)
430
431
/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in import_loop(schema, mutable, raw_data, field_converter, trusted_data, mapping, partial, strict, init_values, apply_defaults, convert, validate, new, oo, recursive, app_data, context)
153 field_context = context
154 try:
--> 155 value = _field_converter(field, value, field_context)
156 except (FieldError, CompoundError) as exc:
157 errors[serialized_field_name] = exc
/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in __call__(self, *args)
354
355 def __call__(self, *args):
--> 356 return self.func(*args)
357
358
/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in import_converter(field, value, context)
382 if value is None or value is Undefined:
383 return value
--> 384 return field.convert(value, context)
385
386
/home/user/anaconda2/lib/python2.7/site-packages/schematics/types/compound.pyc in convert(self, value, context)
34 def convert(self, value, context=None):
35 context = context or get_import_context()
---> 36 return self._convert(value, context)
37
38 def _convert(self, value, context):
/home/user/anaconda2/lib/python2.7/site-packages/schematics/types/compound.pyc in _convert(self, value, context)
131 "Input must be a mapping or '%s' instance" % self.model_class.__name__)
132 if context.convert and context.oo:
--> 133 return model_class(value, context=context)
134 else:
135 return model_class.convert(value, context=context)
TypeError: __init__() takes exactly 1 argument (3 given)
Somewhat weirder, a request like:
client.list_market_catalogue(MarketFilter(market_ids=['1.135391020']))
Works fine.
python 2.7.13, Anaconda 4.4.0, Ubuntu 16.04.2
Any idea what could be causing this?
From the trace it looks to me like the schematics library is your issue. Checking the open issues on the betfair github there is, as of this writing, an open ticket regarding schematics breaking the api. It would appear that the author has left schematics out of the requirements and that version 1.1.1 is required. My guess is you have schematics 2.0 installed on the computer causing the issue.
One way to find this in the future would be to pip freeze the working environment and diff the broken environment. Moreover, when moving to a new machine you can use the output of pip freeze to duplicate the environment and avoid messy version issues like this.

Pyalgotrade Tutorial Attribute Error

I have been googling for a while now, but am still unable to find a solution, or even determine the problem, honestly.
My installation of Python and Pyalgotrade is correct, as verified by the successful imports.
Nonetheless, I can't manage to run the example code in the tutorial, it always throws:
AttributeError: MyStrategy instance has no attribute 'info'
Here's the example code:
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__instrument = instrument
def onBars(self, bars):
bar = bars[self.__instrument]
self.info(bar.getClose())
# Load the yahoo feed from the CSV file
feed = yahoofeed.Feed()
feed.addBarsFromCSV("orcl", "orcl-2000.csv")
# Evaluate the strategy with the feed's bars.
myStrategy = MyStrategy(feed, "orcl")
myStrategy.run()
And the iPython Notebook output:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-f786d1b471f7> in <module>()
18 # Evaluate the strategy with the feed's bars.
19 myStrategy = MyStrategy(feed, "orcl")
---> 20 myStrategy.run()
/usr/local/lib/python2.7/site-packages/pyalgotrade/strategy/__init__.pyc in run(self)
398 self.onStart()
399
--> 400 self.__dispatcher.run()
401
402 if self.__feed.getCurrentBars() != None:
/usr/local/lib/python2.7/site-packages/pyalgotrade/observer.pyc in run(self)
139 subject.start()
140
--> 141 while not self.__stopped and self.__dispatch():
142 pass
143 finally:
/usr/local/lib/python2.7/site-packages/pyalgotrade/observer.pyc in __dispatch(self)
131 nextDateTime = subject.peekDateTime()
132 if nextDateTime == None or nextDateTime == smallestDateTime:
--> 133 subject.dispatch()
134 return ret
135
/usr/local/lib/python2.7/site-packages/pyalgotrade/feed/__init__.pyc in dispatch(self)
95 dateTime, values = self.getNextValuesAndUpdateDS()
96 if dateTime != None:
---> 97 self.__event.emit(dateTime, values)
98
99 def getKeys(self):
/usr/local/lib/python2.7/site-packages/pyalgotrade/observer.pyc in emit(self, *parameters)
51 self.__emitting = True
52 for handler in self.__handlers:
---> 53 handler(*parameters)
54 self.__emitting = False
55 self.__applyChanges()
/usr/local/lib/python2.7/site-packages/pyalgotrade/strategy/__init__.pyc in __onBars(self, dateTime, bars)
386
387 # 1: Let the strategy process current bars and place orders.
--> 388 self.onBars(bars)
389
390 # 2: Place the necessary orders for positions marked to exit on session close.
<ipython-input-1-f786d1b471f7> in onBars(self, bars)
10 def onBars(self, bars):
11 bar = bars[self.__instrument]
---> 12 self.info(bar.getClose())
13
14 # Load the yahoo feed from the CSV file
AttributeError: MyStrategy instance has no attribute 'info'
Has anyone at least a hint on what the problem could be?
Which version of PyAlgoTrade are you using ?
import pyalgotrade
print pyalgotrade.__version__
Copied from question:
So, I updated PyAlgoTrade to 0.15, and now the sample code works. I did not investigate the cause of the error yet, but can safely say that 0.15 works as expected.

Categories

Resources