0

私はJIRA-python 1.0.7を使用しています。特定の問題が発生したため、添付ファイル ID と添付ファイルの URI を取得しようとしています。JIRA-python ドキュメントには、次の属性 issue.fields.attachment issue.fields.attachment.id で添付ファイルにアクセスできると書かれていますが、これらのエラーが発生しています

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'

このドキュメントは、次の方法を使用して添付リソースを取得できることも示唆しています

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

どこで私は間違ってしまったのですか.親切にアドバイスをしてください 私の実際のコードを編集してください

#!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()
4

2 に答える 2

2

今日、バージョン 1.0.7 でもまったく同じ問題が発生しました。属性 'attachment' が見つかりませんが、<tab> を使用すると実際に見つかります。

私のように、問題を最初に取得するために使用issues = jira.search_issues()している可能性がありますか? 返されるオブジェクトには、何らかの理由で「添付ファイル」属性がありません。

ただし、 を呼び出すことで、特定の問題の新しいオブジェクトを取得できますissue = jira.issue(issues[i].key)。このオブジェクトには、'attachment' 属性 (so issue.fields.attachment) があります。

お役に立てれば!

于 2016-06-21T14:26:41.387 に答える