# URI Module fails POST but CURL succeds as shell

**URL:** <https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683>\
**Category:** Ansible Project\
**Created:** [July 6, 2015, 3:53am UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683 "2015-07-06T03:53:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sveera](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sveera](https://forum.ansible.com/u/sveera)\
**Post date:** [July 6, 2015, 3:53am UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/1 "2015-07-06T03:53:07Z")

</div>

I am getting a connection refused socket error :111 when using get\_uri module for POST of a zip file to a url . If i use curl command on shell the task runs without error. How can i fix this issue?

---

<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 6, 2015, 2:06pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/2 "2015-07-06T14:06:47Z")

</div>

What does it show you when you run it in verbose mode?

---

<div class="post-metadata">

**Author:** ![sveera](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sveera](https://forum.ansible.com/u/sveera)\
**Post date:** [July 9, 2015, 1:37am UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/3 "2015-07-09T01:37:43Z")

</div>

Hello, this is the error I get , when i run it in verbose mode.

TASK: [Curl to post to oabc] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\<10.1.3.163\> ESTABLISH CONNECTION FOR USER: ubuntu  
\<10.1.3.163\> REMOTE\_MODULE uri url=‘[http://localhost/api/v1.0/abcd?abcdZipFile=abcd\_v3.0\_20150701.ZIP](http://localhost/api/v1.0/abcd?abcdZipFile=abcd_v3.0_20150701.ZIP)’  
\<10.1.3.163\> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/vagrant/ahafasfhsalf\_Dev.pem” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=120 10.1.3.163 /bin/bash -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188 && echo $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188’  
\<10.1.3.163\> PUT /tmp/tmpGByUla TO /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/uri  
\<10.1.3.163\> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/vagrant/ahafasfhsalf\_Dev.pem” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=120 10.1.3.163 /bin/bash -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=szyrygobamhtrmdhebttkjwsmjgkyuhc] password: " -u root /bin/bash -c '”’“‘echo BECOME-SUCCESS-szyrygobamhtrmdhebttkjwsmjgkyuhc; LANG=C LC\_CTYPE=C /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/uri; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/ \>/dev/null 2\>&1’”‘"’’  
failed: [10.1.3.163] =\> (item=abcd\_v3.0\_Monthly\_Master\_20150701.ZIP) =\> {“failed”: true, “item”: “abcd\_v3.0\_\_20150701.ZIP”}  
msg: Socket error: [Errno 111] Connection refused to [http://localhost/api/v1.0/abcd?abcdZipFile=abcd\_v3.0\_\_20150701.ZIP](http://localhost/api/v1.0/abcd?abcdZipFile=abcd_v3.0__20150701.ZIP)  
…ignoring

---

<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 9, 2015, 2:35am UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/4 "2015-07-09T02:35:32Z")

</div>

where is the api running? can you show the curl command that succeeds?  
where do you run it from?

---

<div class="post-metadata">

**Author:** ![sveera](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sveera](https://forum.ansible.com/u/sveera)\
**Post date:** [July 9, 2015, 6:21pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/5 "2015-07-09T18:21:00Z")

</div>

The playbook below works with CURL in SHELL but not URI

---

<div class="post-metadata">

**Author:** ![sveera](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sveera](https://forum.ansible.com/u/sveera)\
**Post date:** [July 9, 2015, 6:21pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/6 "2015-07-09T18:21:27Z")

</div>

The API is running on 10.1.3.163

---

<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 9, 2015, 6:59pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/7 "2015-07-09T18:59:44Z")

</div>

It looks like you’re missing the port (9004) in the URI call. Which would make sense because it’s getting a “connection refused” socket level error.

---

<div class="post-metadata">

**Author:** ![sveera](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sveera](https://forum.ansible.com/u/sveera)\
**Post date:** [July 9, 2015, 7:50pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/8 "2015-07-09T19:50:12Z")

</div>

I added the port and tested again. here is the error I get.

---

<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 9, 2015, 9:17pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/9 "2015-07-09T21:17:45Z")

</div>

Getting closer. 500 is an internal server error. Do you have access to the server logs? Also, run the playbook with --verbose and set return\_content=yes on the task.

I’d also wrap the url in doublequotes. I’m guess the url string is getting messed up somehow.

---

<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 9, 2015, 10:15pm UTC](https://forum.ansible.com/t/uri-module-fails-post-but-curl-succeds-as-shell/18683/10 "2015-07-09T22:15:15Z")

</div>

Status code 500 is an internal server error which means the application you’re talking had a problem. Might check the logs for the application to see if it reported why it couldn’t handle the request.

I also note that the filename that the uri module is trying to POST is different from the filename in your curl. That might be a clue as well.

-Toshio
