Client Connection OPC UA Python выходит из строя с «BadSecurityPolicyRejected», несмотря на использование правильного сеPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Client Connection OPC UA Python выходит из строя с «BadSecurityPolicyRejected», несмотря на использование правильного се

Сообщение Anonymous »

Код: Выделить всё

Connecting to opc.tcp://172.16.0.1:4844...

C:\Users\Administrator\PycharmProjects\PythonProject1\intro.py:272: RuntimeWarning: coroutine 'Client.set_security_string' was never awaited

client.set_security_string(f"Basic256Sha256,SignAndEncrypt,{cert_path},{key_path}")

RuntimeWarning: Enable tracemalloc to get the object allocation traceback ServiceFault (BadSecurityPolicyRejected, diagnostics: DiagnosticInfo(SymbolicId=None, NamespaceURI=None, Locale=0, LocalizedText=None, AdditionalInfo=None, InnerStatusCode=None, InnerDiagnosticInfo=None))

from server received  in response to CreateSessionRequest Error: The security policy does not meet the requirements set by the server.(BadSecurityPolicyRejected)

Updated status of server ID None to 'Not Running'. Inserted action log for Server ID None: Not Running in 172.16.0.1
< /code>
for server in servers:
endpoint_url = server.EndpointUrl
server_ip = server.ServerIP
print(f"Connecting to {endpoint_url}...")

if not ping_server(server_ip):
print(f"{server_ip} is not reachable.")
update_server_status(cursor, None, "Not Running", server_ip)
continue

try:
# Configure OPC UA client
client = Client(endpoint_url)
client.set_user("DEWA_OPC")
client.set_password("RTeK8QrF9F5G")
client.set_security_string(f"Basic256Sha256,SignAndEncrypt,{cert_path},{key_path}")
await client.connect()  # Await the connection
print(f"Connected to OPC UA server at {endpoint_url}")

update_server_status(cursor, None, "Running", server_ip)

cursor.execute("SELECT [TagName] FROM [admin_db].[dbo].[opc_ua_tag_name]")
tag_names = [row.TagName for row in cursor.fetchall()]

root = client.get_root_node()
historical_data_node = client.get_node("ns=2;s=RealTimeData")  # Adjust the node as needed

# Continuously fetch real-time data for each tag
for tag_name in tag_names:
await fetch_and_insert_data(tag_name, historical_data_node)

await client.disconnect()  # Await disconnection
print("Real-time data fetch cycle completed.")

except Exception as e:
print(f"Error: {e}")
update_server_status(cursor, None, "Not Running", server_ip)

await asyncio.sleep(10)  # Wait for 10 seconds before the next cycle

except Exception as e:
print(f"Error in main loop: {e}")
Я пытаюсь подключиться к серверу OPC UA по адресу opc.tcp: //172.16.0.1: 4844 с помощью Python и библиотеки Asyncua. Я хочу использовать безопасное соединение с Basic256SHA256 Политика безопасности и аутентификации сертификата клиента.

Когда я запускаю это, я получаю следующее предупреждение и ошибку, упомянутые выше. < /P>
  • Утвердил, что сервер поддерживает Basic256sha256 < /code>. /> подтвердил, что cert_path и key_path указывать на допустимые файлы.
  • Посмотрите ошибку и подозревает, что я могу не злоупотреблять set_security_string .
    Как я должен использовать set_string . Asyncua в контексте Async ? И что может вызвать ошибку BadsecurityPolicyRectioned ?


Подробнее здесь: https://stackoverflow.com/questions/795 ... -despite-u
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»