Closed fouadsel88 closed 3 years ago
I also get this error. I can get my code to work by running it a second time. I've been trying to dig into what exactly is happening but I have had no luck so far. I'm not sure where myafserver
is even defined.
I was able to get it to work by commenting out some code and hardcoding the default server name into PIAF.py:
class PIAFDatabase(object):
"""PIAFDatabase
Context manager for connections to the PI Asset Framework database.
"""
version = "0.1.1"
# servers = {
# s.Name: {"server": s, "databases": {d.Name: d for d in s.Databases}}
# for s in AF.PISystems()
# }
servers = {}
# if AF.PISystems().DefaultPISystem:
# default_server = servers[AF.PISystems().DefaultPISystem.Name]
# elif len(servers) > 0:
# default_server = servers[list(servers)[0]]
# else:
# default_server = None
default_server = "your_server_name_here"
I was able to get it to work by commenting out some code and hardcoding the default server name into PIAF.py:
class PIAFDatabase(object): """PIAFDatabase Context manager for connections to the PI Asset Framework database. """ version = "0.1.1" # servers = { # s.Name: {"server": s, "databases": {d.Name: d for d in s.Databases}} # for s in AF.PISystems() # } servers = {} # if AF.PISystems().DefaultPISystem: # default_server = servers[AF.PISystems().DefaultPISystem.Name] # elif len(servers) > 0: # default_server = servers[list(servers)[0]] # else: # default_server = None default_server = "your_server_name_here"
Thank you! This worked for me. My issue was when I made my script an executable file and put it on a computer in a different domain, it couldn't connect the server for some reason...even when PISDK had connection with the PI server.
Thank you all for your answers. I found this link very helpful https://pisquare.osisoft.com/s/question/0D51I00004UHq9c/python-36-and-afsdk-example-pithon If you follow the steps in the link you can use FindPIServer function to find your server
from OSIsoft.AF import *
from OSIsoft.AF.PI import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *
from OSIsoft.AF.UnitsOfMeasure import *
from OSIsoft.AF import UI
Myserver = UI.AFHelper.FindPIServer(yourServerName)
I am able to connect to the PI server, thank you all for sharing this valuables information
Description
When I tried to import the PI package using below code
I got the below error, when i use my personal computer worked fine however when I ran it in my work machine I get this error, is this normal behavior from a protected network? and how I can fix that?
System