# Python OPCUA server connection Issue

**URL:** <https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371>\
**Category:** General\
**Created:** [8 May 2021 18:18 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371 "2021-05-08T18:18:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgethomas08](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@georgethomas08](https://discourse.nodered.org/u/georgethomas08)\
**Post date:** [8 May 2021 18:18 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/1 "2021-05-08T18:18:25Z")

</div>

I can connect with Prosys simultaion server with OPCUA client node in Node Red but when I run python OPCUA it's not at all getting connected Why is it so? Python server - python client is working fine!

Please find the python code below

* * *

from opcua import Server  
from random import randint  
import datetime  
import time

server = Server()

url = "opc.tcp://127.0.0.1:4840"  
server.set\_endpoint(url)

name = "OPC\_SIMULATION\_SERVER"  
addspace = server.register\_namespace(name)

node = server.get\_objects\_node()

Param = node.add\_object(addspace, "Parameters")

Temp = Param.add\_variable(addspace, "Temperature", 0)  
Press = Param.add\_variable(addspace, "Pressure", 0)  
Time = Param.add\_variable(addspace, "Time", 0)

Temp.set\_writable()  
Press.set\_writable()  
Time.set\_writable()

server.start()  
print("Server started at {}".format(url))

while True:  
Temperature = randint(10,50)  
Pressure = randint(200, 999)  
TIME = datetime.datetime.now()

```
print(Temperature, Pressure, TIME)

Temp.set_value(Temperature)
Press.set_value(Pressure)

Time.set_value(TIME)

time.sleep(0.1)

```

* * *

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 May 2021 19:46 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/2 "2021-05-08T19:46:54Z")

</div>

> [@georgethomas08](#):
>
> when I run python OPCUA it's not at all getting connected

I am not sure what you are asking. What do you mean by "when I run python OPCUA" and what isn't getting connected to what?

---

<div class="post-metadata">

**Author:** ![georgethomas08](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@georgethomas08](https://discourse.nodered.org/u/georgethomas08)\
**Post date:** [8 May 2021 19:49 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/3 "2021-05-08T19:49:52Z")

</div>

I'm sorry for missing the word "server", there are opcua simulation server in python, I'm not able to connect with opcua-client node in Node-red

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 May 2021 20:00 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/4 "2021-05-08T20:00:43Z")

</div>

I haven't used that node, but I suggest you start by showing us how you have configured the client node and tell us where you are running the server and what OS/hardware node-red is running on. Also post the terminal log that is shown when you start node-red in a terminal. Then probably someone with experience of the node will be able to help.

---

<div class="post-metadata">

**Author:** ![georgethomas08](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@georgethomas08](https://discourse.nodered.org/u/georgethomas08)\
**Post date:** [8 May 2021 20:14 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/5 "2021-05-08T20:14:51Z")

</div>

I installed `node-red-contrib-opcua`  
I will share the working one first, ie: reading from prosys

 ![Screenshot from 2021-05-09 01-39-44](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c6bf4f25c315f2d8cfb770742a901b5a09bbb9b.png)

 ![Screenshot from 2021-05-09 01-38-25](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f3df08701f7e363002927a89e8128bad32212dce.png)  
 ![Screenshot from 2021-05-09 01-39-55](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/adae5e1a40a42d7794ecea3d157b67504793071c.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 May 2021 20:44 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/6 "2021-05-08T20:44:28Z")

</div>

So that is the working one, I assume. It is the failing one we need.

I note from the screenshot that you appear to be running node-red in Docker. Is that correct? If so I believe that you cannot reference the host via localhost from within the container. I mention that in case that is what you are trying to do.

---

<div class="post-metadata">

**Author:** ![georgethomas08](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@georgethomas08](https://discourse.nodered.org/u/georgethomas08)\
**Post date:** [8 May 2021 21:08 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/7 "2021-05-08T21:08:51Z")

</div>

Hi Colin,

Thanks for the support, Yes the node-red docker only I used, I made it worked I dockerized the python server connect to the same network and its reading now, In addition is there any examples of deploying the docker container in any cloud Kubernetes platform?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 May 2021 10:44 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/8 "2021-05-09T10:44:50Z")

</div>

> [@georgethomas08](#):
>
> is there any examples of deploying the docker container in any cloud Kubernetes platform

I don't know about Kubernetes. There have been posts about that previously so I suggest you start by searching the forum. Then if that doesn't help start a new thread with your question.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 July 2021 10:45 UTC](https://discourse.nodered.org/t/python-opcua-server-connection-issue/45371/9 "2021-07-08T10:45:24Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
