# Updating the uri module

**URL:** <https://forum.ansible.com/t/updating-the-uri-module/18653>\
**Category:** Ansible Developer\
**Created:** [July 1, 2015, 5:10pm UTC](https://forum.ansible.com/t/updating-the-uri-module/18653 "2015-07-01T17:10:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmeickle](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@jmeickle](https://forum.ansible.com/u/jmeickle)\
**Post date:** [July 1, 2015, 5:10pm UTC](https://forum.ansible.com/t/updating-the-uri-module/18653/1 "2015-07-01T17:10:13Z")

</div>

Hi! I’ve been using Ansible for about a month. I recently filed my first PR, and I’m hoping to continue the discussion now that it’s been merged: [https://github.com/ansible/ansible-modules-core/pull/1634](https://github.com/ansible/ansible-modules-core/pull/1634)

The ‘get\_url’ module (and some others) use Ansible’s ‘fetch\_url’, based on urllib2. On the other hand, Ansible’s ‘uri’ module uses httplib2. I’m in an environment with a lot of networking layers (VPN, squid proxy, SOCKS proxy, and SSH tunnels), and I’ve seen their behavior diverge on a few occasions. It would be nice to trust that if ‘get\_url’ works on a machine, ‘uri’ will too.

Is there anything blocking a refactor to use ‘fetch\_url’ instead of httplib2? The module’s comments don’t explain why a different implementation was used. Alternately, if it’s not feasible to use ‘fetch\_url’, would requests be a better dependency than httplib2? The httplib2 code in use seems to be exactly the kind of boilerplate that requests takes care of.

Possibly relevant: AFAICT this is the only module that use httplib2, which would allow removing it as an Ansible dependency.

Thanks,

-James M.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 1, 2015, 5:56pm UTC](https://forum.ansible.com/t/updating-the-uri-module/18653/2 "2015-07-01T17:56:56Z")

</div>

I'm not aware of a reason other than they were written at different times.

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [July 1, 2015, 10:04pm UTC](https://forum.ansible.com/t/updating-the-uri-module/18653/3 "2015-07-01T22:04:47Z")

</div>

I would love a refactor to use fetch\_url instead. That would make it  
so that we don't have to require any additional modules. This is a  
complaint that we've had to field before and it would be nice to be  
able to resolve it.

requests would be a distant second choice but if we did have to do  
that because fetch\_url() wasn't feasible, it would be preferable to  
httplib2 because requests is already installed on more machines than  
httplib2. However, you have to support both the old requests API and  
the more modern one because different distros have older and newer  
versions. The base modules like uri have to remain python-2.4  
compatible to run on RHEL/CentOS5. So we'd have to support the  
version of requests that's available on those platforms (likely  
through EPEL) in addition to the newer version that will be available  
on newer distributions.

(So hopefully, fetch\_url() will be usable here 😉

-Toshio

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [July 2, 2015, 3:01am UTC](https://forum.ansible.com/t/updating-the-uri-module/18653/4 "2015-07-02T03:01:16Z")

</div>

You can find my original, ‘Contemplating a URI module’ email to the list back from back in 2013, here:

[https://groups.google.com/d/msg/ansible-project/A0ND645fc2Y/\_BMtSy0G7iAJ](https://groups.google.com/d/msg/ansible-project/A0ND645fc2Y/_BMtSy0G7iAJ)

which covers the reasons I went with httplib2.

As to why I didn’t go with requests, it had some holes in it’s coverage of python 2.4 and Michael requested that I not use it.

If I was mistaken in any of my reasoning and it makes sense to port it to ‘fetch\_url’ then it’s ok with me 🙂

Romeo

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 2, 2015, 7:51pm UTC](https://forum.ansible.com/t/updating-the-uri-module/18653/5 "2015-07-02T19:51:03Z")

</div>

It seems that the same reasoning still applies, urllib does not  
provide all the methods, requests ... well ... its much better now but  
considering the versions out in the wild and that they rewrote the  
interface at one point its just going to be one issue after another.

It seems httplib might be the least bad option.

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [July 2, 2015, 9:35pm UTC](https://forum.ansible.com/t/updating-the-uri-module/18653/6 "2015-07-02T21:35:23Z")

</div>

> You can find my original, ‘Contemplating a URI module’ email to the list back from back in 2013, here:
> 
> [https://groups.google.com/d/msg/ansible-project/A0ND645fc2Y/\_BMtSy0G7iAJ](https://groups.google.com/d/msg/ansible-project/A0ND645fc2Y/_BMtSy0G7iAJ)
> 
> which covers the reasons I went with httplib2.
> 
> As to why I didn’t go with requests, it had some holes in it’s coverage of python 2.4 and Michael requested that I not use it.
> 
> If I was mistaken in any of my reasoning and it makes sense to port it to ‘fetch\_url’ then it’s ok with me 🙂

Probably not mistaken per se ; jimi-c added support for additional http verbs to fetch\_url at some point. There could be done missing, though. Have to let him know if that’s the case.

[https://github.com/ansible/ansible/blob/devel/lib/ansible/module\_utils/urls.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py)

(Fetch\_url builds on urllib2 to provide us with a function we can call from within ansible to make http requests.)

-Toshio
