Cannot download an attached file data associated with ticket

70 views
Skip to first unread message

SSYED-USER

unread,
Nov 29, 2016, 2:02:18 PM11/29/16
to Assembla API Development
Hi All,

I have been trying to download a file(to get the file content) which is in file attachment list of a ticket. Below is my python code, please have a look:

 import requests, os
def download_file_attachment(space, document_id):
    
    try:
        ASSEMBLA_BASE_URL = 'https://api.assembla.com/v1/'
        space_id = "my-space-id"
        url = os.path.join(ASSEMBLA_BASE_URL, "spaces", space_id, "documents", str(document_id), "download")
        print url
        response = get_assembla(url)
        return response
    except:
        return None
 
def get_assembla(url, params={}, headers={}):
    headers = { 'X-Api-Key': ASSEMBLA_API_KEY,
                'X-Api-Secret' : ASSEMBLA_API_KEY_SECRET,
                'Content-type' : 'application/json' }
    retry_count = 0
    response = None
    while retry_count < 5:
        try:
            response = requests.get(url, params=params, headers=headers, verify=False, allow_redirects=True)
            break
        except:
            retry_count += 1
    return response
 
# Calling below
response = download_file_attachment(space, attribute_document_id)

When im running the above code, im getting 403 response.
This is what I recived in logs:
 "GET /a881ee/bjtzxqedyr47RdacwqjQWU/bcCjksTLCr5Odcdmr6QqzO_1?response-content-disposition=inline%3B%20filename%3D%22my_dict.txt%22%3B%20filename%2A%3DUTF-8%27%27my_dict.txt&Signature=iePt2HSUfrwBnFomYHgQ8gfaGYw%3D&Expires=1480443290&AWSAccessKeyId=0VPMNHAQ0JNX91QHHP02 HTTP/1.1" 403 None

I have also seen this reference link but it didnt help much: http://api-doc.assembla.com/content/ref/documents_download.html

Can anyone please help me that what I am doing wrong?

SSYED-USER

unread,
Nov 30, 2016, 2:01:48 AM11/30/16
to Assembla API Development

The issue is resolved. I just updated the above code by removing this parameter in headers  'Content-type' : 'application/json'. Simply not mentioning any content type and now I am able to download the file content.

Stanislav Kolotinskiy

unread,
Dec 15, 2016, 2:43:55 AM12/15/16
to SSYED-USER, Assembla API Development
Hi,

thanks for providing the solution!

Regards,
Stanislav

--
You received this message because you are subscribed to the Google Groups "Assembla API Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to assembla-api-d...@googlegroups.com.
To post to this group, send email to assembla...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages