Problem with httpget authentification

I have the following python function wich works, but Java asks me for authentification (with a popup) although I pass the good username and password. Is there a way to resolve this problem or a workaround ?

I am on W7, Ignition 7.6 and Java RE 1.7

def httpGetEwonRtValues(lnk,usr,pwd):
import system
rtvalues=[]
logger = system.util.logger(“ewonRTvaluesGetter”)
try:
response = system.net.httpGet(url=lnk,username=usr,password=pwd)
lines=response.split(’\n’)
variableLine=False
for line in lines:
if line.find(’’)!=-1:
break
if variableLine==True:
words=line.split(’;’)
if len(words)==6:
TagId=words[0]
TagName=words[1]
Value=words[2]
AlStatus=words[3]
AlType=words[4]
Quality=words[5]
rtvalue=(TagId,TagName,Value,AlStatus,AlType,Quality)
rtvalues.append(rtvalue)
if line.find(‘TagId’)!=-1 and line.find(‘TagName’)!=-1:
variableLine=True
except:
import sys
from java.lang import Exception
exceptionType, exception, stacktrace = sys.exc_info()
if exceptionType == Exception:
exception = exception.getCause()
exceptionName = exception.class.name
logger.error(exceptionName+" : “+str(exception)+” url: “+lnk+” usr: “+usr+” pwd: "+pwd)
return rtvalues

That is the same problem I ran into when trying to access a password protected server.

I had to use Java authentication before making the httpGet call.

Here are a couple of functions I use to do that.

[code]def set_authentication(username, password):
“”" This function overrides the getPasswordAuthentication method of the java.net.Authenticator so
the login credentials will be supplied to security enabled servers when http requests are initiated.
“”"
from java.net import Authenticator
from java.net import PasswordAuthentication

Authenticator.setDefault(None)
class CustomAuthenticator(Authenticator):
	@staticmethod
	def getPasswordAuthentication():
		return PasswordAuthentication(username, password)
a = CustomAuthenticator()
Authenticator.setDefault(a)

def clear_authentication():
“”" This function clears the credentials from java.net.Authenticator. The previous values are
still cached and will be sent when subsequent calls are made to the same server but this
function should keep the cached credentials from being sent when requests are made to a
different server.
“”"
from java.net import Authenticator
Authenticator.setDefault(None)[/code]

Edited to fix typo

Hello,

Thank’s a lot!!

I have inserted the call of your 2 functions before the call system.db.httpGet and it seems to worh now!!

No more Java authentication popups !!