I'm trying to connect to a Netcool 7.1 Object Server using Python, but I'm running into issues. It seems to be a Sybase type database, but stripped down. I'm using the Sybase module and freetds, but I get the following error when I try to connect:
Traceback (most recent call last):
File "netcool.py", line 12, in <module>
db = Sybase.connect('foo','foo','foo','foo')
File "/usr/lib64/python2.6/site-packages/Sybase.py", line 1194, in connect
datetime, bulkcopy, locale, inputmap, outputmap)
File "/usr/lib64/python2.6/site-packages/Sybase.py", line 850, in __init__
self.connect()
File "/usr/lib64/python2.6/site-packages/Sybase.py", line 898, in connect
status = conn.ct_options(CS_SET, CS_OPT_CHAINXACTS, not self.auto_commit)
File "/usr/lib64/python2.6/site-packages/Sybase.py", line 272, in _servermsg_cb
raise DatabaseError(msg)
Sybase.DatabaseError: Msg 17001, Level 10
No SRV_OPTION handler installed.
Has anyone successfully connected to a Netcool Object Server using Python? Is there any way I can edit the Sybase module to make it work? Worst case scenario, would it be possible to write something that communicates with the nco_sql client? I want the ability to read and write to the DB.
Any help or info would be greatly appreciated.
Eventually I figured this out on my own. If you use the SAP Sybase JDBC drivers (jconn4.jar) in conjunction with the JayDeBeApi module, you can successfully connect and read/write to the object server. This is the only Python solution I could find that works. If anyone else has an different method, feel free to share.
Related
I am trying to use the Cloud Shell to update some user permissions. I am logging in using gcloud sql connect my-instance --user=root
gcloud sql connect my-instance
Whitelisting your IP for incoming connection for 5 minutes...done.
Connecting to database with SQL user [sqlserver].********************************************************************************
Python command will soon point to Python v3.7.3.
Python 2 will be sunsetting on January 1, 2020.
See http://https://www.python.org/doc/sunset-python-2/
Until then, you can continue using Python 2 at /usr/bin/python2, but soon
/usr/bin/python symlink will point to /usr/local/bin/python3.
To suppress this warning, create an empty ~/.cloudshell/no-python-warning file.
The command will automatically proceed in seconds or on any key.
********************************************************************************
> Password:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/mssqlcli/main.py", line 117, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/mssqlcli/main.py", line 110, in main
run_cli_with(mssqlcli_options)
File "/usr/local/lib/python2.7/dist-packages/mssqlcli/main.py", line 43, in run_cli_with
from mssqlcli.mssql_cli import MssqlCli
File "/usr/local/lib/python2.7/dist-packages/mssqlcli/mssql_cli.py", line 18, in <module>
from prompt_toolkit.shortcuts import PromptSession, CompleteStyle
ImportError: cannot import name PromptSession
A) I have made the root user's password so insecure and easy there is no way I am mistyping it.
B) It is the third of January, so I really don't know what this Python version error is on about. I made the file but FYI ~/.cloudshell did not exist so I had to make it first. Even so, it just suppresses the version warning, the main error persists when I try to log in.
The documentation acknowledges there are a couple other login methods using glcoud beta sql connect, but that gets me another error
2020/01/04 18:38:41 Rlimits for file descriptors set to {&{8500 1048576}}
2020/01/04 18:38:41 invalid json file "/tmp/tmp.s38C662KKr/legacy_credentials/me#gmail.com/adc.json": open /tmp/tmp.s38C662KKr/legacy_credentials/me#gmail.com/adc.json: no such file or directory
ERROR: (gcloud.beta.sql.connect) Failed to start the Cloud SQL Proxy.
Same for alpha.
This is the first thing I have typed into Cloud Shell, so I can't imagine what could have broken PromptSession.
How can I resolve this error and log into SQL Server using Cloud Shell?
There most likely is an issue while attempting to connect from the Cloud Shell (I managed to connect from a Compute Engine instance with this command); possibly related to the Python run-time / environment variable. It has been reported here. Engineering is aware and are looking into it.
I am trying to connect my raspberry pi to a Bluetooth OBD adapter. I have verified that the OBD device is working by connecting to it from the android phone using Torque lite app.
I am following this tutorial to connect the raspberry pi to the OBD adapter. I am able to pair with the OBD adapter and then trust it. Then I manually create the "/dev/rfcomm0" abstraction. As per the tutorial "screen /dev/rfcomm0" is supposed to print some output. But for me it just says "Screen is terminating" and it exits.
I tried running the "obd_reader.py" script, but it is throwing the following error:
python obd_reader.py
Ports:
['/dev/rfcomm0']
[obd.obd] ======================= python-OBD (v0.6.1) =======================
[obd.obd] Explicit port defined
[obd.elm327] Initializing ELM327: PORT=/dev/rfcomm0 BAUD=auto PROTOCOL=auto
Traceback (most recent call last):
File "obd_reader.py", line 11, in <module>
connection = obd.OBD(ports[0])
File "/usr/local/lib/python2.7/dist-packages/obd/obd.py", line 58, in __init__
self.__connect(portstr, baudrate, protocol) # initialize by connecting and loading sensors
File "/usr/local/lib/python2.7/dist-packages/obd/obd.py", line 85, in __connect
self.interface = ELM327(portstr, baudrate, protocol)
File "/usr/local/lib/python2.7/dist-packages/obd/elm327.py", line 137, in __init__
if not self.set_baudrate(baudrate):
File "/usr/local/lib/python2.7/dist-packages/obd/elm327.py", line 265, in set_baudrate
return self.auto_baudrate()
File "/usr/local/lib/python2.7/dist-packages/obd/elm327.py", line 293, in auto_baudrate
response = self.__port.read(1024)
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 460, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
I tried a suggestion provided here, but there was no change in output. This was the change suggested:
You need to add the SP profile editing this:
sudo nano /etc/systemd/system/dbus-org.bluez.service
Then add the compatibility flag -C for adding the SP to sdptool. Modify the lines from the file above to:
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
I feel that I am creating or configuring the rfcomm device in the wrong way. But not sure how to fix this. Can someone please suggest a solution?
It seems that line 27 of the script you are running you are missing a dot in the query:
res = connection.query(obd.commands[command])
Tt should be like this as far as I know:
res= connection.query(obd.commands.[command])
I have been trying to use stanford-corenlp-python which is a python wrapper using this github repo.
However, while storing the results I get the following error:
Traceback (most recent call last):
File "client.py", line 14, in <module>
result = nlp.parse("Hello world! It is so beautiful.")
File "client.py", line 11, in parse
return json.loads(self.server.parse(text))
File "/home/kenden/deeshacodes/stanford-corenlp-python/jsonrpc.py", line 934, in __call__
return self.__req(self.__name, args, kwargs)
File "/home/kenden/deeshacodes/stanford-corenlp-python/jsonrpc.py", line 906, in __req
raise RPCTransportError(err)
jsonrpc.RPCTransportError: [Errno 111] Connection refused
How do I solve this? Also, is there any other way to use coreNLP in python?
May be you can try this stanfordcorenlp.
It's very simple.
from stanfordcorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP(r'G:/JavaLibraries/stanford-corenlp-full-2016-10-31/')
sentence = 'Guangdong University of Foreign Studies is located in Guangzhou.'
print 'Tokenize:', nlp.word_tokenize(sentence)
print 'Part of Speech:', nlp.pos_tag(sentence)
print 'Named Entities:', nlp.ner(sentence)
print 'Constituency Parsing:', nlp.parse(sentence)
print 'Dependency Parsing:', nlp.dependency_parse(sentence)
Although convient, it is not as stable as native Python wrapper. "The project is just a wraper to parse the json data requested from the Java Server backend."
This is a bit of a non-answer, but have you considered using the CoreNLP server? For example, here or here? You can also directly make requests to a running server and get JSON responses: http://stanfordnlp.github.io/CoreNLP/corenlp-server.html (or protobuf, if you're feeling adventurous).
So im trying to connect to a CoaP Resource using this python library https://github.com/chrysn/aiocoap . The library uses python 3.4 and i have 3.4 installed and set as the interpreter to use with this (Im on Windows 7 btw). Still im getting this error message, when executing the clientGET.py file. Same for the server file.
C:\Python34\python.exe C:/Learning/PyCoap/aiocoap/clientGET.py
Traceback (most recent call last):
File "C:/Learning/PyCoap/aiocoap/clientGET.py", line 34, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "C:\Python34\lib\asyncio\base_events.py", line 268, in run_until_complete
return future.result()
File "C:\Python34\lib\asyncio\futures.py", line 277, in result
raise self._exception
File "C:\Python34\lib\asyncio\tasks.py", line 236, in _step
result = next(coro)
File "C:/Learning/PyCoap/aiocoap/clientGET.py", line 20, in main
protocol = yield from Context.create_client_context()
File "C:\Learning\PyCoap\aiocoap\aiocoap\protocol.py", line 510, in create_client_context
transport, protocol = yield from loop.create_datagram_endpoint(protofact, family=socket.AF_INET6)
File "C:\Python34\lib\asyncio\base_events.py", line 675, in create_datagram_endpoint
waiter)
File "C:\Python34\lib\asyncio\selector_events.py", line 68, in _make_datagram_transport
address, waiter, extra)
File "C:\Python34\lib\asyncio\selector_events.py", line 911, in __init__
super().__init__(loop, sock, protocol, extra)
File "C:\Python34\lib\asyncio\selector_events.py", line 452, in __init__
self._extra['sockname'] = sock.getsockname()
OSError: [WinError 10022] Ein ungultiges Argument wurde angegeben
Process finished with exit code 1
I didn't explore this in a real Python, as I don't have a Windows machine with Python 3.4 handy, but it seems to me that this could be a bug in asyncio. Its UDP socket creation probably simply doesn't work on Windows. Do some experimenting on the lower level, looking at what aiocoap is doing, and try to prove me wrong.
It's supposed to work, documentation only mentions ProactorEventLoop as not supporting UDP.
The error condition is described in Socket.error: Invalid Argument supplied .
aiocoap.protocol.Context.create_client_context() seems to be doing the right thing according to asyncio documentation, but _SelectorTransport.__init__() will always call sock.getsockname() before any packets are sent, at which point the socket will not be bound to an address (according to the linked SO question) and getsockname() will fail on Windows.
You might want to retry with a current version of Python and aiocoap (current development version, after 0.4a1). Windows used not to be supported in aiocoap, and is still not supporting all of CoAP, but now uses a socket implementation that is aware of some limitations in the Windows socket API.
I'm getting the error:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at
(http://www.w3.org/2001/XMLSchema.x sd), failed
when passing a Doctor (constructed with ImportDoctor) to the suds Client constructor.
I'm working on two Windows machines, both of them got the same version of suds installed, but only one of them rises the error above.
Could someone guide me here to know why this error rises?, so I can figure out what's missing on the machine where it happens?.
Thanks in advance!!!.
UPDATE: I don't really know if this is important, but it's worth noting that my Windows machine that is rising the error is an Amazon Web Services instance. At my local machine everything's working well!.
UPDATE: Here's some code I ran at the python interpreter of the machine I mentioned. Here you can detail how the error is rising...
>>> from suds.client import Client
>>> from suds.xsd.doctor import ImportDoctor, Import
>>> missing_import = Import("http://www.w3.org/2001/XMLSchema")
>>> missing_import.filter.add("http://tempuri.org/")
>>> doctor = ImportDoctor(missing_import)
>>> client = Client("http://etcfulfill.ebooks.com/Fulfillment.asmx?wsdl")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "suds\client.py", line 112, in __init__
self.wsdl = reader.open(url)
File "suds\reader.py", line 152, in open
d = self.fn(url, self.options)
File "suds\wsdl.py", line 159, in __init__
self.build_schema()
File "suds\wsdl.py", line 220, in build_schema
self.schema = container.load(self.options)
File "suds\xsd\schema.py", line 95, in load
child.dereference()
File "suds\xsd\schema.py", line 323, in dereference
midx, deps = x.dependencies()
File "suds\xsd\sxbasic.py", line 422, in dependencies
raise TypeNotFound(self.ref)
suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
>>> client = Client("http://etcfulfill.ebooks.com/Fulfillment.asmx?wsdl", doctor=doctor)
No handlers could be found for logger "suds.xsd.sxbasic"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "suds\client.py", line 112, in __init__
self.wsdl = reader.open(url)
File "suds\reader.py", line 152, in open
d = self.fn(url, self.options)
File "suds\wsdl.py", line 159, in __init__
self.build_schema()
File "suds\wsdl.py", line 220, in build_schema
self.schema = container.load(self.options)
File "suds\xsd\schema.py", line 93, in load
child.open_imports(options)
File "suds\xsd\schema.py", line 305, in open_imports
imported = imp.open(options)
File "suds\xsd\sxbasic.py", line 542, in open
result = self.download(options)
File "suds\xsd\sxbasic.py", line 567, in download
raise Exception(msg)
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
UPDATE:
I realized that suds connections always open in TCP increasing ports, and if it reaches the maximum TCP port (65535) then it starts opening again from the minimum TCP port available, so there's no problem with this.
The problem shows up when using suds ImportDoctor, because it has to open a previous connection to the location where the import should be retrieved, and for some reason, if the system reaches the maximum TCP port count, then suds somehow assumes that there's no TCP port available to open the connection for obtaining the import, and in consecuence it throws the exception:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
I repeat, this only happens if suds has to open this previous connection for obtaining the import. If ImportDoctor is not used, then suds has no problem if the TCP port count reaches its maximum, it just restarts at the minimum port available.
Does anyone has any clue on how to resolve this issue???. I'd really appreciate the help!!!.
I've figured out what the problem was. The schema that was missing from the WSDL I was trying to use with suds was:
http://www.w3.org/2001/XMLSchema
And the XSD file for this schema is at:
http://www.w3.org/2001/XMLSchema.xsd
So when I used suds ImportDoctor to add this schema import, sometimes the w3.org domain was denying my access (don't know why really) and that's why this error was rising:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
What did I do to solve this problem?. I just downloaded this schema to my machine and used suds ImportDoctor to retrieve this import locally.
And that was it!!!. Confusing bug!!!. But SOLVED.