# uri module change

**URL:** <https://forum.ansible.com/t/uri-module-change/18226>\
**Category:** Ansible Developer\
**Created:** [May 14, 2015, 2:41am UTC](https://forum.ansible.com/t/uri-module-change/18226 "2015-05-14T02:41:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [May 14, 2015, 2:41am UTC](https://forum.ansible.com/t/uri-module-change/18226/1 "2015-05-14T02:41:45Z")

</div>

Hi guys,

I’m after a bit of feedback on the uri module.

The doc has the following example:

```auto
- uri: url=https://your.jira.example.com/rest/api/2/issue/
       method=POST user=your_username password=your_pass
       body="{{ lookup('file','issue.json') }}" force_basic_auth=yes
       status_code=201 HEADER_Content-Type="application/json"

```

```auto
All good. However, if you write pure json in the file 'issue.json' you will get the following problem when you run the module:

```

> Traceback (most recent call last):  
> File “/root/.ansible/tmp/ansible-tmp-1431569317.82-251864554272416/uri”, line 2049, in   
> main()  
> File “/root/.ansible/tmp/ansible-tmp-1431569317.82-251864554272416/uri”, line 407, in main  
> resp, content, dest = uri(module, url, dest, user, password, body, method, dict\_headers, redirects, socket\_timeout)  
> File “/root/.ansible/tmp/ansible-tmp-1431569317.82-251864554272416/uri”, line 306, in uri  
> resp, content = h.request(url, method=method, body=body, headers=headers)  
> File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1605, in request  
> (response, content) = self.\_request(conn, authority, uri, request\_uri, method, body, headers, redirections, cachekey)  
> File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1353, in \_request  
> (response, content) = self.\_conn\_request(conn, request\_uri, method, body, headers)  
> File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1290, in \_conn\_request  
> conn.request(method, request\_uri, body, headers)  
> File “/usr/lib64/python2.6/httplib.py”, line 920, in request  
> self.\_send\_request(method, url, body, headers)  
> File “/usr/lib64/python2.6/httplib.py”, line 960, in \_send\_request  
> self.send(body)  
> File “/usr/lib64/python2.6/httplib.py”, line 765, in send  
> self.sock.sendall(str)  
> File “”, line 1, in sendall  
> TypeError: sendall() argument 1 must be string or buffer, not dict

The json file gets interpreted as a Python dict and httplib.py errors out when it’s passed a dict instead of a string.

My solution was to do this before the request (line 302 in uri module):

if isinstance(body, dict):  
body = json.dumps(body)

I just wanted to know if this is worth a PR or would a better solution be to stop the file being interpreted as a dict in the first place?

---

<div class="post-metadata">

**Author:** ![Beatrice\_Floyd](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Beatrice\_Floyd](https://forum.ansible.com/u/Beatrice_Floyd)\
**Post date:** [May 18, 2015, 10:54pm UTC](https://forum.ansible.com/t/uri-module-change/18226/2 "2015-05-18T22:54:38Z")

</div>

Hi Rob,  
I ran into this problem using the uri module when I started adding variables into the body. The only solution I could get to work was the change you suggested. I think it would definitely be worth a PR.  
Thanks,  
Beatrice.

- local\_action:  
module: uri  
url: [http://XXXXX:4567/stashes](http://XXXXX:4567/stashes)  
method: POST  
status\_code: 201  
HEADER\_Content-Type: application/json  
body: ‘{“content”:{“message”:“temp”}, “path”:“silence/a/{{domain}}”}’

---

<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:** [May 19, 2015, 4:54pm UTC](https://forum.ansible.com/t/uri-module-change/18226/3 "2015-05-19T16:54:17Z")

</div>

If you try running the uri module that's in the devel branch,  
[https://github.com/ansible/ansible-modules-core/blob/devel/network/basics/uri.py](https://github.com/ansible/ansible-modules-core/blob/devel/network/basics/uri.py)  
are you able to use the body\_format=json parameter to make this work?

The module probably still needs a PR to update the documentation,  
though. If you could confirm that the new parameter is working and  
then submit a PR to update the documentation that would be great!

-Toshio

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [May 21, 2015, 3:25am UTC](https://forum.ansible.com/t/uri-module-change/18226/4 "2015-05-21T03:25:59Z")

</div>

I’ll test this next week and submit doc PR

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [May 28, 2015, 5:29am UTC](https://forum.ansible.com/t/uri-module-change/18226/5 "2015-05-28T05:29:45Z")

</div>

Tested and working. Thanks for the work Toshio. PR for doc update - [https://github.com/ansible/ansible-modules-core/pull/1430](https://github.com/ansible/ansible-modules-core/pull/1430)
