1

i am using JIRA-python 1.0.7. Given a particular issue i am trying to get the attachment id and attachment uri. the JIRA-python document says that i can access the attachment with the following attributes issue.fields.attachment issue.fields.attachment.id But however i am getting these error

In [23]: issue.fields.attachment
--------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/lib/python3.4/site-packages/jira/jirashell.py in <module>()
----> 1 issue.fields.attachment
AttributeError: type object 'PropertyHolder' has no attribute 'attachment'

The document also suggests that i can get an attachment resource using the following method

jira.attachment(id)

In [24]: issue=jira.issue('OPENNLP-830')
In [25]: issue.id
Out[25]: '12931716'
In [26]: jira.attachment(12931716)
---------------------------------------------------------------------------
JIRAError                                 Traceback (most recent call last)
/usr/lib/python3.4/site-packages/jira/jirashell.py in <module>()
----> 1 jira.attachment(12931716)
JIRAError: JiraError HTTP 404 url: https://issues.apache.org/jira/rest/api/2/attachment/12931716 details: /tmp/jiraerror-0n8wkhwj.tmp

where have i gone wrong.kindly do advice edit My actual code

#!usr/bin/python

from jira import JIRA
import psycopg2
from creating_db import create_db  

def main():
    #Establishing connection with JIRA 
    options = {'server': 'https://issues.apache.org/jira'}
    jira = JIRA(options)
    #Creating the necessary database
    create_db()
    #Connecting to the database
    try:
        conn=psycopg2.connect("dbname='issue_db' host='master' user='hema' password='password'")
    except psycopg2.Error as e:
        print (e)
    cur=conn.cursor ()
    #This command returns an object of type ResultList. ResultList has an attribute called 'total' which gives us the total number of issues filled so far in a given project.
    issue_count=jira.search_issues('project=OPENNLP')
    #Iteratively receiving the issues 
    for count in range(0, issue_count.total,50):
        issue_in_proj = jira.search_issues('project=OPENNLP', startAt = count, maxResults = 50)
        issue_attachment=[issue.fields.attachment for issue in issue_in_proj] # the documentation says its issue.fields.attachment and not attachments
        for i in range( len(issue_in_proj)):
            for j in range(len(issue_attachment[i]):
                cur.execute('''INSERT INTO attachments VALUES(%s,%s)''',  [(issue_id[i],issue_attachment[i][j].id)])
    conn.commit()
    cur.close
    conn.close 

if __name__=="__main__":
    main()
Hemaa mathavan
  • 348
  • 4
  • 15

2 Answers2

2

I've had the exact same problem with version 1.0.7 today: attribute 'attachment' not found, but when I use <tab> it is actually found.

Are you perhaps using issues = jira.search_issues() to retrieve issues first, like I do? The objects it returns are missing the 'attachment' attribute for some reason.

However, you can retrieve a new object for a particular issue by calling issue = jira.issue(issues[i].key). This object will have an 'attachment' attribute (so issue.fields.attachment).

Hope this helps!

pip
  • 21
  • 2
  • Good call. I think this is exactly his issue. – darksideofthesun Jun 21 '16 at 21:20
  • @pip yeah i am using jira.search_issue(). but i tried your method and still i get the same error -attribute 'attachment' not found.The attachment attribute cant be found even when i view the raw form(issue.raw) of the object.i tried including the 'attachment' field in the object by using the command issue =jira.search_issues('project=OPENNLP', startAt = count, maxResults = 50, fields ='attachment').but still the attachment attribute doesnt get included – Hemaa mathavan Jun 22 '16 at 05:27
1

The parser in jira is not parsing out the attachment key returned by the rest response in the JSON document. You'll need to issues = jira.search_issues("assignee in (currentUser())", fields=["attachment"]