# httpGet vs. urllib2 slow at fetching data from the web

**URL:** <https://forum.inductiveautomation.com/t/httpget-vs-urllib2-slow-at-fetching-data-from-the-web/22953>\
**Category:** Ignition\
**Created:** [February 27, 2019, 10:45pm UTC](https://forum.inductiveautomation.com/t/httpget-vs-urllib2-slow-at-fetching-data-from-the-web/22953 "2019-02-27T22:45:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [February 27, 2019, 10:45pm UTC](https://forum.inductiveautomation.com/t/httpget-vs-urllib2-slow-at-fetching-data-from-the-web/22953/1 "2019-02-27T22:45:08Z")

</div>

Can anyone tell me why urllib2.urlopen takes so long to fetch file/binary data from a website while system.net.httpGet fetches data quickly. I’m talking apples vs. oranges here because httpGet doesn’t work well with binary data and that’s what I need. Take for example this file [https://i.imgur.com/BcN64PR.gif](https://i.imgur.com/BcN64PR.gif). Its an animated gif. If I use httpGet, I’ll either get a scrambled animation or just the single frame. if I use urllib2.urlopen() followed by .read()…and subsequent StringUtil.toBytes(), then I get the complete file intact just as you would in a browser but takes nearly 5 seconds for code to run.  
FWIW, I have read through a mind numbing posts across the web of other folks using ImageIO or ByteArrayOutputStreams or InputStreams…but with no success for me. urllib2 works…but very slow.

Try running this in a script console and check out the file.

```auto
import urllib2
url = 'https://i.imgur.com/BcN64PR.gif'
#response = urllib2.urlopen(url)
#filebytes = response.read()
filebytes = system.net.httpGet(url)

if filebytes != None:
	#from org.python.core.util import StringUtil
	#filebytes = StringUtil.toBytes(filebytes)
	filepath = system.file.saveFile("peanutbutterjellytime.gif")
	system.file.writeFile(filepath,filebytes)
#end if

```

This is what httpGet 's you.  
 ![httpGet](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/156b0b699bd986e27ac6b162a0d962f478d748d7.jpeg)

---

<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 27, 2019, 11:12pm UTC](https://forum.inductiveautomation.com/t/httpget-vs-urllib2-slow-at-fetching-data-from-the-web/22953/2 "2019-02-27T23:12:22Z")

</div>

Huh, heard complaints that urllib2 is slower but it only takes ~75ms to download that gif with urllib2 from my machine.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [February 27, 2019, 11:53pm UTC](https://forum.inductiveautomation.com/t/httpget-vs-urllib2-slow-at-fetching-data-from-the-web/22953/3 "2019-02-27T23:53:11Z")

</div>

Strange. If I keep running the script multiple times, I will eventually get sub 1-second. But if I pause and try running again, I get a five second delay with urllib2. This is with any file from any site. httpGet consistently returns quickly.

 ![delay](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e419a6e2a1752e8a114cc6d593471ead11042f0b.png)

I tried executing again quickly after cancelling the save dialog and it returns with less than 1 second delay

 ![nodelay](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/ea409aa5b6ae2f2f806d017f5802134ca2bc3cc7.png)
