Hi guys,
I’m after a bit of feedback on the uri module.
The doc has the following example:
- 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"
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?