httpGet

In FPMI I have the following code which works well. It gives an I/O error in Ignition.

[code]#screen scrape from the gateway to get a list of the FactoryPMI datasources
if event.propertyName == “ListInit”:
address = system.util.getGatewayAddress()
source = system.net.httpGet(“http://%s/gateway/Gateway?tab=datasources” % address)
findStr = “Datasource '
endFindStr = “
’”

Headers = ["DataSource"]
Names = []
pos = source.find(findStr)
while pos != -1:
	pos2 = source.find(endFindStr)
	#save it to a dataset
	print source[pos+18:pos2]
	Names.append([source[pos+18:pos2]])
	source = source[pos2+8:]
	pos = source.find(findStr)

event.source.data = system.dataset.toDataSet(Headers, Names)[/code]

Error:

[code]Traceback (innermost last):
File “event:propertyChange”, line 4, in ?
IOError: http

at org.python.core.Py.IOError(Py.java)
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.httpGet(AbstractNetUtilities.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:286)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyObject.invoke(PyObject.java)
at org.python.pycode._pyx61.f$0(<event:propertyChange>:4)
at org.python.pycode._pyx61.call_function(<event:propertyChange>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:367)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:138)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:280)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at $Proxy1.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.PMIComboBox.fireDynChange(PMIComboBox.java:872)
at com.inductiveautomation.factorypmi.application.binding.util.DynamicPropertyUtil.setPropertyValue(DynamicPropertyUtil.java:217)
at com.inductiveautomation.factorypmi.application.components.PMIComboBox.setPropertyValue(PMIComboBox.java:860)
at com.inductiveautomation.factorypmi.application.binding.AbstractPropertyAdapter.updateTarget(AbstractPropertyAdapter.java:111)
at com.inductiveautomation.factorypmi.application.binding.SQLPropertyAdapter.propertyChange(SQLPropertyAdapter.java:208)
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$PropertyChangeUpdater.run(QueryManager.java:501)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.0.2 (b4482)
Java: Sun Microsystems Inc. 1.6.0_18
[/code]

Looks like you’re porting over a Click-to-chart setup.

There are a few things going on here. None of them have to do with the httpGet function.

  1. system.util.getGatewayAddress() returns a different format than in FactoryPMI. Notably, it returns the “http://” directly, so the address you’re feeding httpGet is like “http://http://192.168…(etc)”

  2. Even after you fixed that, it wouldn’t work. This method is “screen-scraping” the gateway webpage to get a list of all datasources. The Gateway’s web interface has changed a bit (to put it mildly) from FactoryPMI to Ignition - this will no longer work.

  3. Because of exactly this problem, 7.0.3 which is coming out later today has a system.db.getConnections() function.

I went ahead and change this to a query to get the info I needed.

Ok, you might want to change it to use the getConnections() call, because we don’t guarantee screen-scraping backwards compatibility.