Hi all,
We are trying to post some alarms to a slack channel, and using this test code causes it to fail (and kills our script console as well):
from urllib import request, parse
import json
def send_message_to_slack(text, slackURL):
post = {"text": "{0}".format(text)}
try:
json_data = json.dumps(post)
req = request.Request(slackURL,
data=json_data.encode('ascii'),
headers={'Content-Type': 'application/json'})
response = request.urlopen(req)
except Exception as e:
print("Exception: " + str(e))
send_message_to_slack('Test Alarm')
We get an error message when trying to open a script console, and it prevents us from access. Here is our error message:
Exception in thread "AWT-EventQueue-0" ImportError: Cannot import site module and its dependencies: Error loading module net: Traceback (most recent call last):
File "<module:net>", line 6, in <module>
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\urllib.py", line 26, in <module>
import socket
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\socket.py", line 3, in <module>
from _socket import (
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\_socket.py", line 12, in <module>
from collections import namedtuple, Iterable
ImportError: cannot import name Iterable
Determine if the following attributes are correct:
* sys.path: [C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib, C:\Users\acecola\.ignition\cache\resources\platform\jython-2.7.1-ia2.jar\00000000FD8C6322\Lib, __classpath__, __pyclasspath__/]
This attribute might be including the wrong directories, such as from CPython
* sys.prefix: C:\Users\acecola\.ignition\cache\resources\platform\jython-2.7.1-ia2.jar\00000000FD8C6322
This attribute is set by the system property python.home, although it can
be often automatically determined by the location of the Jython jar file
You can use the -S option or python.import.site=false to not import the site module
Exception in thread "AWT-EventQueue-0" ImportError: Cannot import site module and its dependencies: Error loading module net: Traceback (most recent call last):
File "<module:net>", line 6, in <module>
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\urllib.py", line 26, in <module>
import socket
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\socket.py", line 3, in <module>
from _socket import (
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\_socket.py", line 12, in <module>
from collections import namedtuple, Iterable
ImportError: cannot import name Iterable
Determine if the following attributes are correct:
* sys.path: [C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib, C:\Users\acecola\.ignition\cache\resources\platform\jython-2.7.1-ia2.jar\00000000FD8C6322\Lib, __classpath__, __pyclasspath__/]
This attribute might be including the wrong directories, such as from CPython
* sys.prefix: C:\Users\acecola\.ignition\cache\resources\platform\jython-2.7.1-ia2.jar\00000000FD8C6322
This attribute is set by the system property python.home, although it can
be often automatically determined by the location of the Jython jar file
You can use the -S option or python.import.site=false to not import the site module
Exception in thread "AWT-EventQueue-0" ImportError: Cannot import site module and its dependencies: Error loading module net: Traceback (most recent call last):
File "<module:net>", line 6, in <module>
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\urllib.py", line 26, in <module>
import socket
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\socket.py", line 3, in <module>
from _socket import (
File "C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib\_socket.py", line 12, in <module>
from collections import namedtuple, Iterable
ImportError: cannot import name Iterable
Determine if the following attributes are correct:
* sys.path: [C:\Users\acecola\.ignition\cache\gw172.16.40.251_8088\C0\pylib, C:\Users\acecola\.ignition\cache\resources\platform\jython-2.7.1-ia2.jar\00000000FD8C6322\Lib, __classpath__, __pyclasspath__/]
This attribute might be including the wrong directories, such as from CPython
* sys.prefix: C:\Users\acecola\.ignition\cache\resources\platform\jython-2.7.1-ia2.jar\00000000FD8C6322
This attribute is set by the system property python.home, although it can
be often automatically determined by the location of the Jython jar file
You can use the -S option or python.import.site=false to not import the site module
I assume this is some sort of import error, removing the code causes it to work again, and we can open our script console after that.
Another problem, after deleting that function and replacing it with some other function (a simple gateway logger), it looks like we not longer have “system” imported into the script, so we have to type in “import system” at the top of the script. Re-naming the script allows us to ignore “import system”, but even deleting the script and making a new script with the same name continually gives us this importing issue. Any ideas as to what is happening here?
We get this error:
Traceback (most recent call last):
File "<buffer>", line 4, in <module>
File "<module:net>", line 3, in logAlarm
NameError: global name 'system' is not defined
It looks like deleting scripts doesn’t actually get rid of them (we deleted / re-named the modified script, but it still appeared to be callable in our script console). Unless the script console is the real culprit here?
Best,
Roger