# Error in system.net.httpClient.get()

**URL:** <https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648>\
**Category:** Ignition\
**Created:** [March 20, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648 "2024-03-20T17:46:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![compuzak](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@compuzak](https://forum.inductiveautomation.com/u/compuzak)\
**Post date:** [March 20, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/1 "2024-03-20T17:46:48Z")

</div>

system.net.httpClient

#Set the endpoint URL  
url = "[https://api.openweathermap.org/data/2.5/weather](https://api.openweathermap.org/data/2.5/weather)"

#Declare a variable for system function we are using  
myClient = system.net.httpClient()

# this works

response = myClient.get(url, {"lat":38.652330, "lon":-121.189773, "appid":"MYAPPID"})

# this doesn't

myData = '{"lat":38.652330, "lon":-121.189773, "appid":"MYAPPID"}'  
response = myClient.get(url, myData)

How can I use the variable myData in this .get() command? If gives me an error on the lines that say "this doesn't work" and I am not sure why.

Also, if I have headers to add to the request, do I use:  
myClient.head(url, myHdrData)

Does the .head command use the same syntax as the .get data?

---

<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:** [March 20, 2024, 5:47pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/2 "2024-03-20T17:47:53Z")

</div>

> [@compuzak](#):
>
> If gives me an error on the lines that say "this doesn't work"

What error does it give you?

---

<div class="post-metadata">

**Author:** ![compuzak](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@compuzak](https://forum.inductiveautomation.com/u/compuzak)\
**Post date:** [March 20, 2024, 5:48pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/3 "2024-03-20T17:48:50Z")

</div>

ValueError: Invalid URL - Illegal character in query at index 48: [https://api.openweathermap.org/data/2.5/weather?](https://api.openweathermap.org/data/2.5/weather?){"lat":38.652330, "lon":-121.189773, "appid":"8a639bbc5012f64a5e334c89b9d02e28"}

---

<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:** [March 20, 2024, 5:48pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/4 "2024-03-20T17:48:51Z")

</div>

> [@compuzak](#):
>
> I am not sure why.

Because you are making `myData` a string. The working form submits a dictionary and lets httpClient package it properly.

---

<div class="post-metadata">

**Author:** ![compuzak](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@compuzak](https://forum.inductiveautomation.com/u/compuzak)\
**Post date:** [March 20, 2024, 5:50pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/5 "2024-03-20T17:50:07Z")

</div>

how do i convert it to a dictionary

---

<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:** [March 20, 2024, 5:50pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/6 "2024-03-20T17:50:34Z")

</div>

`myData = '{"lat":38.652330, "lon":-121.189773, "appid":"MYAPPID"}'`

Should be

`myData = {"lat":38.652330, "lon":-121.189773, "appid":"MYAPPID"}`

---

<div class="post-metadata">

**Author:** ![compuzak](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@compuzak](https://forum.inductiveautomation.com/u/compuzak)\
**Post date:** [March 20, 2024, 5:51pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/7 "2024-03-20T17:51:39Z")

</div>

Thanks both of you, does the header work the same syntax?

---

<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:** [March 20, 2024, 5:55pm UTC](https://forum.inductiveautomation.com/t/error-in-system-net-httpclient-get/87648/8 "2024-03-20T17:55:12Z")

</div>

According to the documentation - `Dictionary headers - A dictionary of HTTP headers to send with the request. Defaults to None. [optional] `

> **[system.net.httpClient | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-httpClient)**
>
> Provides a general use object that can be used to send and receive HTTP requests.

Answer seems to be yes. Seems like you should do something like `headers = {'someKey':'someValue'}`. You create a dictionary with curly brackets and pairs of keys and values' `myDict = {'key1':'someValue1', 'key2':'anotherValue'}` etc.

Highly recommend checking out some python 2.7 course. Here's a cheat sheet version I refer my coworkers to [Learn Python 2 (legacy) in Y Minutes](https://learnxinyminutes.com/docs/pythonlegacy/)
