Jenkins API not working on local jenkins

Hello,
I have a script which works perfectly from my local laptop to give build information
for key in app: server=jenkins.Jenkins(‘https://xxxxxxxxxxxxxxx’,username=‘sdsdsdsdsd’,password=‘sdusdusdysudysudysu’)
values = app[key]
for v in values:
#print ("the application deployment time of " + key + ’ is ’ , v)
last_build_number = server.get_job_info(v)[‘lastSuccessfulBuild’][‘number’]
build_info = server.get_build_info(v,last_build_number)
duration_in_milliseconds = build_info[‘duration’]

The same script when I run on the jenkins server locally(ie,on the jenkins server itself where we have alljobs its not working.) I keep getting
self, “Failed to establish a new connection: %s” % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f46feba8748>: Failed to establish a new connection: [Errno 111] Connection refused
I tried changing to localhost, checked /etc/hosts nothing seems to be helping. On the server not sure why its not able pull data .can some one please help.
Thanks