# Import requests module error in python scripting

**URL:** <https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207>\
**Category:** Ignition Early Access\
**Tags:** perspective, ignition81, scripting\
**Created:** [May 31, 2022, 1:49pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207 "2022-05-31T13:49:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baskar\_Arumugam](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Baskar\_Arumugam](https://forum.inductiveautomation.com/u/Baskar_Arumugam)\
**Post date:** [May 31, 2022, 1:49pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/1 "2022-05-31T13:49:55Z")

</div>

Hello Everyone,  
I am using the **requests** module in python scripting for getting the real time weather data based on the location.  
I am getting the error while running my script. I attached the image file here kindly help me to solve this error

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/e/7ede6d8f24cc8a027997984afef779f7bcb3d85d.jpeg)  
here is my code for your reference  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/5/45b05f98b71e429eb13381d30b16ca2ee5d74e16.jpeg)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 31, 2022, 1:56pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/2 "2022-05-31T13:56:57Z")

</div>

You should try using `system.net.httpClient`  
[https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient](https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient)  
and with that you can do `get` requests like

```auto
# Create the JythonHttpClient.
client = system.net.httpClient()
 
# Sent a GET request.
response = client.get("https://httpbin.org/get", params={"a": 1, "b": 2})
 
# Validate the response.
if response.good:
    # Do something with the response
    print response.json['args']['a']

```

One thing to note in your script is you use an `os.environ['weather']`. All perspective scripts run in the gateway so this is always telling your Ignition Gateway to get the system variable `weather` from the gateway computer - this does not change user to user, so I would suggest either hardcoding it into a gateway tag and referencing that, or if you want it to be different user to user, use a session variable.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 31, 2022, 3:06pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/3 "2022-05-31T15:06:16Z")

</div>

Whatever is going on here with the codec registry error is ultimately a Jython bug. Migrating to system.net.httpClient is going to be far less headache than trying to maintain an increasingly out-of-date version of `requests` over time.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 31, 2022, 3:12pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/4 "2022-05-31T15:12:18Z")

</div>

@Baskar_Arumugam A general rule of thumb to follow is to look first is there is some `system.*` implementation of what you need to do before trying to use a jython library.

Jython has some randomly interspersed issues in various packages, so it is much safer (and probably faster, definitely more maintainable) to use Ignition’s implementation whenever possible.

---

<div class="post-metadata">

**Author:** ![Baskar\_Arumugam](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Baskar\_Arumugam](https://forum.inductiveautomation.com/u/Baskar_Arumugam)\
**Post date:** [June 1, 2022, 4:13am UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/5 "2022-06-01T04:13:25Z")

</div>

ok Let me try and get back to you, Thankyou for your response

---

<div class="post-metadata">

**Author:** ![srinivasan\_s](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@srinivasan\_s](https://forum.inductiveautomation.com/u/srinivasan_s)\
**Post date:** [June 10, 2025, 9:02am UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/6 "2025-06-10T09:02:06Z")

</div>

> [@bkarabinchak.psi](#):
>
> gateway

How you guys ensuring if the connection was failed?

My scenario is , I am connecting to third party application using syste,.net.httpClient, if response good everything is ok, but lost connection of third party system , how to handle ? Below code is not working

```python
try:
		client = system.net.httpClient()
		response = client.get("http://192.168.43.75:5000/data")

		if response.good:
			system.perspective.openPopup("testing", "popup1")
		else:
			system.util.getLogger("FlaskCheck").info("Received response but status not OK")

	except Exception as e:
            system.util.getLogger("FlaskCheck").error("Error while connecting to Flask server: " + str(e))

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 10, 2025, 12:44pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/7 "2025-06-10T12:44:08Z")

</div>

Jython's `Exception` cannot catch Java exceptions, as they are not in the same class hierarchy. Use another `except Throwable, t:` clause for those. Add `from java.lang import Throwable` outside that function.

---

<div class="post-metadata">

**Author:** ![srinivasan\_s](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@srinivasan\_s](https://forum.inductiveautomation.com/u/srinivasan_s)\
**Post date:** [June 11, 2025, 5:54pm UTC](https://forum.inductiveautomation.com/t/import-requests-module-error-in-python-scripting/60207/8 "2025-06-11T17:54:00Z")

</div>

Thank you @pturmel . It works
