# Ansible unable to except any other body format except raw and jason in the uri module and upload a zip or a jar via POST method

**URL:** <https://forum.ansible.com/t/ansible-unable-to-except-any-other-body-format-except-raw-and-jason-in-the-uri-module-and-upload-a-zip-or-a-jar-via-post-method/27582>\
**Category:** Ansible Project\
**Created:** [May 21, 2018, 6:05pm UTC](https://forum.ansible.com/t/ansible-unable-to-except-any-other-body-format-except-raw-and-jason-in-the-uri-module-and-upload-a-zip-or-a-jar-via-post-method/27582 "2018-05-21T18:05:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apu\_Mondal](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Apu\_Mondal](https://forum.ansible.com/u/Apu_Mondal)\
**Post date:** [May 21, 2018, 6:05pm UTC](https://forum.ansible.com/t/ansible-unable-to-except-any-other-body-format-except-raw-and-jason-in-the-uri-module-and-upload-a-zip-or-a-jar-via-post-method/27582/1 "2018-05-21T18:05:47Z")

</div>

Zip file not getting POST to the server with the uri module in Ansible.

These are the codes I am trying to execute

- name: Transfering the Proxies  
uri:  
headers:  
Authorization: ‘{{API\_USER\_PASS\_BASE64\_ENCRYPT}}’  
Content-Type: “application/octet-stream”  
url: [https://api.enterprise.apigee.com/v1/organizations/{{API\_ORG}}/apis?action=import&name={{](https://api.enterprise.apigee.com/v1/organizations/%7B%7BAPI_ORG%7D%7D/apis?action=import&name=%7B%7B)proxy\_name }}-{{API\_ENVIRONMENT}}  
#body: “{{ lookup(‘file’,‘{{ path }}/{{bundle\_name}}/apigee/proxies/{{proxy\_name}}–hughes-dev-test-dev.zip’) }}” → doesn’t work  
src: /{{ path }}/{{bundle\_name}}/apigee/proxies/{{proxy\_name}}–hughes-dev-test-dev.zip  
body\_format: raw  
status\_code: 201, 200  
method: POST  
register: version

It gives the following error:  
“json”: {  
“code”: “messaging.config.beans.InvalidBundle”,  
“contexts”: ,  
“message”: “Bundle is invalid. Empty bundle”  
},

Also it sets the “content\_type”: “application/json”, at the top of the message like this:

The full traceback is:  
File “/tmp/ansible\_NyKoMf/ansible\_module\_uri.py”, line 468, in main  
uresp[‘location’] = absolute\_location(url, uresp[‘location’])

fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“connection”: “Close”,  
“content”: “{\n “code” : “messaging.config.beans.InvalidBundle”,\n “message” : “Bundle is invalid. Empty bundle”,\n “contexts” : \n}”,  
“content\_length”: “122”,  
“content\_type”: “application/json”,  
“date”: “Mon, 14 May 2018 19:03:48 GMT”,  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backup”: null,  
“body”: null,  
“body\_format”: “raw”,  
“client\_cert”: null,  
“client\_key”: null,  
“content”: null,  
“creates”: null,  
“delimiter”: null,  
“dest”: null,  
“directory\_mode”: null,  
“follow”: false,  
“follow\_redirects”: “safe”,  
“force”: false,  
“force\_basic\_auth”: false,  
“group”: null,  
“headers”: {  
“Authorization”: “Basic YXBvb3J2YS5tb25kYWxAaHVnaGVzLmNvbTphcG9vcnZhNw==”,  
“Content-Type”: “application/octet-stream”  
},  
“http\_agent”: “ansible-httpget”,  
“method”: “POST”,  
“mode”: null,  
“owner”: null,  
“regexp”: null,  
“remote\_src”: null,  
“removes”: null,  
“return\_content”: false,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“src”: “/var/tmp/APIGEE\_COM\_R001\_B-001\_P-001/apigee/proxies/FapProxy–hughes-dev-test-dev.zip”,  
“status\_code”: [  
“201”,  
" 200"  
],  
“timeout”: 30,  
“unsafe\_writes”: null,  
“url”: “[https://api.enterprise.apigee.com/v1/organizations/hughes-dev/apis?action=import&name=FapProxy-sa-dev](https://api.enterprise.apigee.com/v1/organizations/hughes-dev/apis?action=import&name=FapProxy-sa-dev)”,  
“url\_password”: null,  
“url\_username”: null,  
“use\_proxy”: true,  
“validate\_certs”: true  
}  
},  
“json”: {  
“code”: “messaging.config.beans.InvalidBundle”,  
“contexts”: ,  
“message”: “Bundle is invalid. Empty bundle”  
},  
“msg”: “Status code was not [201, 200]: HTTP Error 400: Bad Request”,  
“redirected”: false,  
“server”: “Apigee LB”,  
“status”: 400,  
“url”: “[https://api.enterprise.apigee.com/v1/organizations/hughes-dev/apis?action=import&name=FapProxy-sa-dev](https://api.enterprise.apigee.com/v1/organizations/hughes-dev/apis?action=import&name=FapProxy-sa-dev)”  
}

1. 
  - name: Transfering the Proxies

```auto
  uri:
    headers:
     Authorization: '{{API_USER_PASS_BASE64_ENCRYPT}}'
     Content-Type: "application/zip"
    url: https://api.enterprise.apigee.com/v1/organizations/{{API_ORG}}/apis?action=import&name={{ proxy_name }}-{{API_ENVIRONMENT}}
    body: "{{ lookup('file','{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip') }}"
    #src: '{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip'
    #body_format: raw
    status_code: 201, 200
    method: POST
  register: version

```

Please check and provide information on how to properly POST a zip file.

##### ISSUE TYPE- Bug Report

- Feature Idea
- Documentation Report

##### COMPONENT NAME

URI Module

##### ANSIBLE VERSION

```auto
ansible 2.4.2.0

```

##### CONFIGURATION##### OS / ENVIRONMENT

Red Hat Enterprise Linux Server 7.3 (Maipo)

##### STEPS TO REPRODUCE

```auto
- name: Transfering the Proxies
  uri:
    headers:
     Authorization: '{{API_USER_PASS_BASE64_ENCRYPT}}'
     Content-Type: "application/zip"
    url: https://api.enterprise.apigee.com/v1/organizations/{{API_ORG}}/apis?action=import&name={{ proxy_name }}-{{API_ENVIRONMENT}}
    body: "{{ lookup('file','{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip') }}"
    #src: '{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip'
    #body_format: raw
    status_code: 201, 200
    method: POST
  register: version

---
- name: Transfering the Proxies
  uri:
    headers:
     Authorization: '{{API_USER_PASS_BASE64_ENCRYPT}}'
     Content-Type: "multipart/form-data"
    url: https://api.enterprise.apigee.com/v1/organizations/{{API_ORG}}/apis?action=import&name={{ proxy_name }}-{{API_ENVIRONMENT}}
    #body: "{{ lookup('file','{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip') }}"
    src: '{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip'
    #body_format: raw
    status_code: 201, 200
    method: POST
  register: version

- name: Transfering the Proxies
  uri:
    headers:
     Authorization: '{{API_USER_PASS_BASE64_ENCRYPT}}'
     Content-Type: "application/octet-stream"
    url: https://api.enterprise.apigee.com/v1/organizations/{{API_ORG}}/apis?action=import&name={{ proxy_name }}-{{API_ENVIRONMENT}}
    #body: "{{ lookup('file','{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip') }}" --> doesn't work
    src: /{{ path }}/{{bundle_name}}/apigee/proxies/{{proxy_name}}--hughes-dev-test-dev.zip
    body_format: raw
    status_code: 201, 200
    method: POST
  register: version

```

##### EXPECTED RESULTS

The zip file should be uploaded to the server.

##### ACTUAL RESULTS

Right now as uri module is not working I am using the curl command instead.  
But I want my code not to have dependency on the linux commands. Hence trying to use the uri module.

- name: Transfering the Proxies  
command: ‘curl -X POST --header “Authorization: Basic YXBvb3J2YS5tb25kYWxAaHVnaGVzLmNvbTphcG9vcnZhNw==” -F “file=@/{{path}}/{{bundle\_name}}/apigee/proxies/{{proxy\_name}}–hughes-dev-test-dev.zip” “[https://api.enterprise.apigee.com/v1/organizations/{{API\_ORG}}/apis?action=import&name={{](https://api.enterprise.apigee.com/v1/organizations/%7B%7BAPI_ORG%7D%7D/apis?action=import&name=%7B%7B)proxy\_name }}-{{API\_ENVIRONMENT}}”’  
register: version  
Neither src nor body parameter is able to POST a zip or jar file to the server.

---

<div class="post-metadata">

**Author:** ![Fabio\_Martins](https://avatars.discourse-cdn.com/v4/letter/f/cab0a1/32.png) [@Fabio\_Martins](https://forum.ansible.com/u/Fabio_Martins)\
**Post date:** [April 3, 2019, 1:31pm UTC](https://forum.ansible.com/t/ansible-unable-to-except-any-other-body-format-except-raw-and-jason-in-the-uri-module-and-upload-a-zip-or-a-jar-via-post-method/27582/2 "2019-04-03T13:31:28Z")

</div>

I am facing exactly the same issue when trying to upload a jar file over a [Flink REST endpoint](https://ci.apache.org/projects/flink/flink-docs-stable/monitoring/rest_api.html#jars-upload).

I tried both with curl and postman, it works flawlessly, but using Ansible URI module, I am getting the error message: FAILED! =\> {“changed”: false, “content”: “”, “msg”: “Status code was -1 and not [200]: Request failed: \<urlopen error [Errno 104] Connection reset by peer\>”, “redirected”: false, “status”: -1, “url”: "http://:8081/jars/upload}

Any idea, or should I continue using the shell module with curl (I don’t like it, but it’s the only way it works for now).

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 3, 2019, 5:56pm UTC](https://forum.ansible.com/t/ansible-unable-to-except-any-other-body-format-except-raw-and-jason-in-the-uri-module-and-upload-a-zip-or-a-jar-via-post-method/27582/3 "2019-04-03T17:56:43Z")

</div>

What does your task look like?

Also, the original report is against 2.4.2 which by now is almost 1.5 years old, and the uri module has since seen a lot of changes.  
What version do you run?

Dick
