Search code examples
pythonxml-rpcbugzilla

How to attach file via "Bugzilla XMLRPC access module"


I am working on bugzilla xml-rpc by using "Bugzilla XMLRPC access module" developed in python.

How I can attach/download bugzilla file by using this module ?

According to guideline of API get_attachments_by_bug($bug_id) retrieves and returns the attachments.

But this function didn't worked for me, I got following error message.

<type 'exceptions.AttributeError'>: 'Bugzilla4' object has no attribute 'get_attachments_by_bug'

Any help would be appreciated.


Solution

  • FYI: I am in contact with supplier of python-bugzilla tool and here I got response from them.

    "Not all bugzilla XMLRPC APIs are wrapped by python-bugzilla, that's one of them.

    The 'bugzilla' command line tool that python-bugzilla ships has commands for attaching files and downloading attachments, take a look at the code there for guidance."


    I've figured out the way how to download/upload attachment by using "Bugzilla XMLRPC access module"

    you need to pass the id of attached file as parameter to the following function

    Download:

    downloaded_file = bz.download_attachment(attachment_id)
    file_name = str(downloaded_file.name)
    

    Upload:

    kwards = {
        'contenttype':'application/octet-stream',
       # 'filename': file_path     #there could be more parameters if needed
    } 
    
    #attachfile method will return the id of attached file 
    bz.attachfile(bug_id, file_path, file_name, **kwards) 
    

    However attached file got corrupted due to some xmp-rpc API's internal methods described here, here and here, that's another issue :)