RTD client in Python - python

my goal is to get the updates of an rtd server in python
I've following call in excel which is working:
=RTD("xrtd.xrtd";;"EUCA")
For python I've found following client library: https://github.com/brotchie/pyrtd/blob/master/rtd/client.py
I tried to get a simple example where I can connect to the server
import sys
sys.path.append(".")
from client import RTDClient
name = "xrtd.xrtd"
try:
client = RTDClient(name)
client.connect(False)
client.register_topic('EUCA')
except Exception as identifier:
print(str(name) + " error : " + str(identifier))
My first problem was that I've used 64bit python, but after I solved this I receive following exception from the connect():
xrtd.xrtd error : This COM object can not automate the makepy process
please run makepy manually for this object
I've no idea what I've to do now. I've python experience but no experience with COM Objects

Try this
import pythoncom
from rtd import RTDClient
if __name__ == '__main__':
time = RTDClient('xrtd.xrtd')
time.connect()
time.register_topic('EUCA')
while 1:
pythoncom.PumpWaitingMessages()
if time.update():
print time.get('EUCA')

Related

Output of Python script differ depending on way of activation

hei guys,
I have an executable python script, say get_data.py (located in project_x/src/) which is working properly, when started by: python get_data.py . It gets data (a list of id's which are necessary for further calculations) from a database via mysql.connector and then processes these data in parallel (via multiprocessing) using pool.map.
BUT it is supposed to be started by an .exe-file (located in project_x/exec/)[EDIT: This .exe uses the php command exec() to directly addresses my python script]. This is not working properly but ending in the try-except-block (in wrapper_fun) when catching the (unknown) mistake and not terminating when deleting the try-except-commands.
Do you have any idea what could be going wrong? I would appreciate any idea. I tried logging but there seems to be a permission problem. My idea is that the connection the db cannot be established and therefore there are no id's.
def calculations():
do_something...
def wrapper_fun(id):
try:
calculations(id)
except Exception:
return(False)
if __name__ == "__main__":
import multiprocessing
import mysql.connector
from mysql.connector import Error
host_name = <secret_1>
user_name = <secret_2>
passt = <secret_3>
connection = None
try:
connection = mysql.connector.connect(
host=host_name,
user=user_name,
passwd=user_password
)
except Error as err:
print(f"Error: '{err}'")
d = pd.read_sql_query(query, connection,coerce_float=False)
connection.close()
id_s = list(d.ids)
results = [pool.map(wrapper_fun,id_s)]
...

Python script crashes when I run opc.write () using OpenOpc

I am making a python program to write variables to an opc DA server.
I have the connection and others, but when trying to write values ​​for a variable, the program does not respond and a windows error message appears saying:
My code:
import OpenOPC
import sys
opc = OpenOPC.client()
servers = opc.servers()
idServer = int(2)
print('connecting to opc server:', servers[idServer])
opc.connect(servers[idServer])
print('connection okey:', servers[idServer])
write = opc.write(('variableName', 1))
print('write:', write)
input('> ')
Does anyone know why the program crashes when it reaches that part? Thanks a lot

Invalid syntax error on python version while running python idle

I am working on a tcp client-server python socket program where I have written server code to sent a simple message to the client . However when I run the server side in python idle I get invlalid syntax error and a red mark on the python version . I don't know where the problem is and I would appreciate your help with this specific task .
Image where error happens :
I press run and then run module and I get :
My code :
Server :
import sys
from socket import *
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('localhost',1234))
serverSocket.listen()
data = "Network labs"
while 1 :
connectionSocket ,addr = serverSocket.accept()
connectionSocket.send(data)
connectionSocket.close()
Client :
import sys
from socket import *
clientSocket = socket(AF_INET,SOCK_STREAM)
server_address=('localhost',1234)
clientSocket.connect(server_address)
sentence = clientSocket.recv(1024)
print(sentence)
clientSocket.close()
You tried to run the log of a shell session, complete with non-code startup message text and non-code prompts as python code. But the session log is not python code. "Python" might be, but "Python 3" is not valid code and so python reports a SyntaxError. This has nothing to do with running the code from an IDLE editor. If you run server.py from a command line or from any other python-aware editor or IDE, you would see the same.
To run server.py, you must remove the non-code parts -- the startup message and prompts. In general, you would also have to remove output, but there is none in your example. So you should end up with
import sys
from socked import *
...
In other words, the cleaned-up server code you listed in your question, which is not the code you ran in the screenshot to get the error message.

Cannot work with Stem and Tor

I want to work with Tor through Stem module.The following is my code to get connected with Tor:
import sys
from stem.connection import connect
if __name__ == '__main__':
controller = connect()
if not controller:
sys.exit(1) # unable to get a connection
print 'Tor is running version %s' % controller.get_version()
controller.close()
However, i get following error when running the code:Unable to connect to tor. Are you sure it's running?
I turned on Tor and tested the code again and nothing happened. The problem is this line:
if __name__ == '__main__':
controller = connect()
Even if I enter the connect() method to Python interpreter I get the error. What is the error and how can I fix it?

Using Pyro4 to get the system information

I try to using the Pyro4 on autotesting, but now I confused for some ability for Pyro4.
Does there existed some method to get the system information by the Pyro4 object.
In my ideas, I expose a pyro object that can get the system information, and the remote machine can using this object to show the system information. But on my code, the remote machine always show the server information. I guess that I misunderstand or misuse the Pyro4
Sorry for this stupid question, i'm the newbie for Pyro4. The follow is my sample code.
The server exposes the pyro object
# Server.py
#! /usr/bin/env python
import Pyro4
import os
class Ex(object):
def run(self):
print os.uname()
if __name__ == "__main__":
daemon = Pyro4.Daemon()
ns = Pyro4.locateNS()
uri = daemon.register(Ex())
ns.register("ex", uri)
print uri
daemon.requestLoop()
and the client using the Pyro object
# Remote
#! /usr/bin/env python
import Pyro4
if __name__ == "__main__":
uri = raw_input("input the uri> ")
fn = Pyro4.Proxy(uri)
fn.run()
p.s
I know i can get the os information on the client side, but I want to use the Pyro object to get the information instead client does this itself.
I got the answer!
Just using the Pyro4.utils.flame. This module can provides the ability to using the module or function on remote machine.
Following is the sample code:
The remote machine
python -Wignore -m Pyro4.utils.flameserver --host <yourIP> --port 9999
The host
#! /usr/bin/env python
import Pyro4.utils.flame
if __name__ == "__main__":
flame = Pyro4.utils.flame.connect("192.168.16.29:64024")
os = flame.module("os")
print os.listdir('.')

Categories

Resources