Ignition Py module error

Hello,

I need your help on scripting.
I am executing a script where i need to import requests lib
Import Requests
.“some script”.

Upon executing I get following error
ImportError : no module names requests

does this means there is missing requests file in pylib folder, if yes how do I fix this.

Thanks.

requests is not a built in standard library; even on a standard Python installation, you have to manually fetch it. Also, Ignition 7.9 is using Jython 2.5, so you’ll have to find an older version of requests that works with 2.5.
Once you’ve tracked down a version that should work, you can manually add it to the user-lib/pylib folder on the gateway and it’ll be synced to clients and designers for you.

1 Like

Will this file work.

That’s requests version 2.5.0. I have no idea if it’s going to work on Python 2.5, but given the latest version is 2.26, it seems unlikely their versions are aligned with Python major versions.

This thread/KBA may be helpful.

Stepping back a bit - what script are you trying to execute? If it's got a dependency on requests, then it may have other dependencies that aren't met by the Jython 2.5 environment you're in. Where did this script come from and what is it supposed to do?

For simply executing http requests, there's lots of options in Ignition, even in 7.9, including the builtin system.net.httpGet, for instance.

below is the script i am trying to execute, I have masked some info , pls ignore that

import os

import requests #for API call

import json

session = requests.Session()

session.trust_env = False

proxy = “http://abc.com:8080

os.environ[‘http_proxy’] = proxy

os.environ[‘https_proxy’] = proxy

url = “https://abc.com/xyz/zyzTemp1/

token = “xyz”

headers = {‘Authorization’: token}

response = session.get(url, headers=headers, verify = False)

json_response = response.json()

print(“Got REsponse!”)

print (json_response)

print("\n\nPrinting siteId")

siteID = json_response[‘result’][0][‘siteId’]

print(result[‘siteId’])

print(siteID)

https://docs.inductiveautomation.com/display/DOC79/system.net.httpGet
https://docs.inductiveautomation.com/display/DOC79/system.util.jsonDecode

Between these two functions, you should be able to do the same thing, no need to use requests.

1 Like

Thanks, sure will try

Hello @PGriffith ,

I tried the above function using httpGet but It returns Http response code : 403.
Same parameters as mentioned below returns proper data in POSTMAN.

url = “https://abc.com:443/api/site/*/tag/tag1?filter=NOATTARB

token = ‘some verified and valid token’

headers = {‘Accept’: ‘application/json’,‘Authorization’: token}]
payload = {}

source = system.net.httpGet(url,headers=headers,bypassCertValidation = True)

noaaJSON = system.util.jsonDecode(source)
print noaaJSON

Thanks

solution modification in above code:
source = system.net.httpGet(url,headerValues=headers,bypassCertValidation = True)

I managed to solve the above problem,
Issue was i was referencing wrong parameter for httpGet, instead of hearders it should have been headerValues.
Now the code works just fine.

Thanks :grin: :brain:

For reference, if you ever need to do something similar in 8.0+, you’ll want system.net.httpClient - Ignition User Manual 8.0 - Ignition Documentation

3 Likes