# \[SOLVED\] Does anyone know how to make a WebRequest in Python/Ignition?

**URL:** <https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [February 16, 2022, 5:58pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226 "2022-02-16T17:58:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [February 16, 2022, 5:58pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226/1 "2022-02-16T17:58:43Z")

</div>

Good morning,

I am converting the following code:

```auto
myRequest = (HttpWebRequest)WebRequest.Create(this.URL); // create request
myRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(this.BasicAuthAccount + ":" + this.BasicAuthPassword)));
myRequest.Method = Method.ToString();
myRequest.KeepAlive = false;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ReadWriteTimeout = 1000;

if (this.HasData)//Append data for send
{
    byte[] byData = Encoding.ASCII.GetBytes(this.JsonifyString); // convert POST data to bytes
    myRequest.ContentLength = byData.Length;
    // Add the post data to the web request
    outputStream = myRequest.GetRequestStream();
    outputStream.Write(byData, 0, byData.Length);
    outputStream.Close();
}
```

I think I use this Ignition method:  
[https://docs.inductiveautomation.com/display/DOC81/system.net.httpPut](https://docs.inductiveautomation.com/display/DOC81/system.net.httpPut)

And I came up with the following code:

```auto
url = "http://192.168.1.7/do_value/slot_0/ch_0"
contentType = "application/x-www-form-urlencoded"
putData = {"Ch":0, "Val": 0}
connectTimeout = 1000
readTimeout = 1000
username = "root"
password = "00000000"
 
system.net.httpPut(url, contentType, putData, connectTimeout, readTimeout, username, password)
```

And I packaged this code into an Ignition button script and am getting the following error:

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 10, in <module>
IOError: Unexpected end of file from server
```

Does anyone know what this error means?

---

<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:** [February 16, 2022, 6:06pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226/2 "2022-02-16T18:06:58Z")

</div>

You’re better off using [system.net.httpClient - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient) and then from there using the .put() method. Try it with httpClient first and see if the issue persists.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [February 16, 2022, 6:12pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226/3 "2022-02-16T18:12:39Z")

</div>

I think you’re trying to use the POST method, not PUT (based on comments in what you’re trying to replicate), so that could be part of the problem as well.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [February 16, 2022, 6:17pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226/4 "2022-02-16T18:17:54Z")

</div>

I am getting a response 411 length required.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4c897f00e821e46ced86f11e47e2db94af3bb3fd.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 16, 2022, 6:30pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226/5 "2022-02-16T18:30:43Z")

</div>

Try sending the JSON as `data`, not `params`. Right now you are calling PUT with an empty request body.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [February 16, 2022, 6:36pm UTC](https://forum.inductiveautomation.com/t/solved-does-anyone-know-how-to-make-a-webrequest-in-python-ignition/56226/6 "2022-02-16T18:36:32Z")

</div>

That was the key… thank you Kevin and others.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e0b9e19d3df3d85523b307e63a389490e223270b.png)
