2014-02-21 78 views
1
from jira.client import JIRA 
jira = JIRA(options, basic_auth=('user', 'password'))  
issues = jira.search_issues('project=titan') 
print issues 

[]JIRA的Python search_issues()返回空列表訪問JIRA通蟒蛇

以下教程。登錄和其他方法工作正常,但我不能讓這個方法返回任何東西。如果我把!=而不是=我仍然得不到任何東西。有任何想法嗎?使用真實的用戶和密碼。有許多問題,我可以單獨訪問它們,如: 問題= jira.issue( 'TITAN-NNN')

JIRA版本6.1.3 =蟒蛇 版本2.7.3 =

+1

在瀏覽器中輸入JQL並查看JIRA更改它的內容。也許TITAN全部大寫? – mdoar

回答

0

打開調試看看會發生什麼:

import httplib 
httplib.HTTPConnection.debuglevel= 1 

實例連接到公共JIRA:

>>> from jira.client import JIRA 
>>> import httplib 
>>> httplib.HTTPConnection.debuglevel= 1 
>>> options = { 
...  'server': 'https://jira.atlassian.com' 
... } 
>>> jira = JIRA(options) 
>>> issues = jira.search_issues('project=JSD') 
send: 'GET /rest/api/2/search?jql=project%3DJSD&startAt=0&maxResults=50 HTTP/1.1\r\nHost: jira.atlassian.com\r\nUser-Agent: python-requests/2.2.1 CPython/2.7.5 Darwin/13.0.0\r\nAccept-Encoding: gzip, deflate, compress\r\nAccept: */*\r\nX-Atlassian-Token: nocheck\r\n\r\n' 
reply: 'HTTP/1.1 200 OK\r\n' 
header: Server: nginx 
header: Date: Wed, 26 Feb 2014 06:17:33 GMT 
header: Content-Type: application/json;charset=UTF-8 
header: Transfer-Encoding: chunked 
header: Connection: keep-alive 
header: X-AREQUESTID: 377x7779615x3 
header: X-ASEN: TestSEN 
header: X-AUSERNAME: anonymous 
header: Cache-Control: no-cache, no-store, no-transform 
header: X-Content-Type-Options: nosniff 
header: X-Robots-Tag: noarchive 
header: Vary: Accept-Encoding 
header: Content-Encoding: gzip 
header: Set-Cookie: __atl_path=172.24.36.107.1393395450345419; path=/; expires=Sat, 24-Feb-24 06:17:30 GMT; domain=.atlassian.com 
header: Set-Cookie: atlassian.xsrf.token=AKVY-YUFR-9LM7-97AB|ecb611160886e0c356f238dc407f015375fffb40|lout; Path=/ 
header: Set-Cookie: JSESSIONID=DA80ADFD3371C4FA2B06F54037B48BB9; Path=/ 
>>> print issues 
[<JIRA Issue: key=u'JSD-361', id=u'319731'>, <JIRA Issue: key=u'JSD-360', id=u'319715'>, <JIRA Issue: key=u'JSD-359', id=u'319714'>, <JIRA Issue: key=u'JSD-358', id=u'319676'>, <JIRA Issue: key=u'JSD-357', id=u'319459'>, <JIRA Issue: key=u'JSD-356', id=u'319436'>, <JIRA Issue: key=u'JSD-355', id=u'319225'>, <JIRA Issue: key=u'JSD-354', id=u'319201'>, <JIRA Issue: key=u'JSD-352', id=u'319192'>, <JIRA Issue: key=u'JSD-351', id=u'319189'>, <JIRA Issue: key=u'JSD-350', id=u'319177'>, <JIRA Issue: key=u'JSD-349', id=u'318912'>, <JIRA Issue: key=u'JSD-348', id=u'318911'>, <JIRA Issue: key=u'JSD-347', id=u'318846'>, <JIRA Issue: key=u'JSD-346', id=u'318840'>, <JIRA Issue: key=u'JSD-345', id=u'318539'>, <JIRA Issue: key=u'JSD-344', id=u'318537'>, <JIRA Issue: key=u'JSD-343', id=u'318492'>, <JIRA Issue: key=u'JSD-342', id=u'318459'>, <JIRA Issue: key=u'JSD-340', id=u'318303'>, <JIRA Issue: key=u'JSD-338', id=u'318128'>, <JIRA Issue: key=u'JSD-337', id=u'318039'>, <JIRA Issue: key=u'JSD-336', id=u'318021'>, <JIRA Issue: key=u'JSD-335', id=u'318020'>, <JIRA Issue: key=u'JSD-334', id=u'318014'>, <JIRA Issue: key=u'JSD-333', id=u'317923'>, <JIRA Issue: key=u'JSD-332', id=u'317908'>, <JIRA Issue: key=u'JSD-331', id=u'317829'>, <JIRA Issue: key=u'JSD-330', id=u'317825'>, <JIRA Issue: key=u'JSD-329', id=u'317821'>, <JIRA Issue: key=u'JSD-328', id=u'317803'>, <JIRA Issue: key=u'JSD-327', id=u'317801'>, <JIRA Issue: key=u'JSD-326', id=u'317800'>, <JIRA Issue: key=u'JSD-325', id=u'317798'>, <JIRA Issue: key=u'JSD-324', id=u'317769'>, <JIRA Issue: key=u'JSD-323', id=u'317747'>, <JIRA Issue: key=u'JSD-322', id=u'317646'>, <JIRA Issue: key=u'JSD-321', id=u'317603'>, <JIRA Issue: key=u'JSD-320', id=u'317601'>, <JIRA Issue: key=u'JSD-319', id=u'317599'>, <JIRA Issue: key=u'JSD-318', id=u'317541'>, <JIRA Issue: key=u'JSD-317', id=u'317499'>, <JIRA Issue: key=u'JSD-316', id=u'317462'>, <JIRA Issue: key=u'JSD-315', id=u'317460'>, <JIRA Issue: key=u'JSD-314', id=u'317440'>, <JIRA Issue: key=u'JSD-313', id=u'317436'>, <JIRA Issue: key=u'JSD-312', id=u'317358'>, <JIRA Issue: key=u'JSD-311', id=u'317355'>, <JIRA Issue: key=u'JSD-310', id=u'317353'>, <JIRA Issue: key=u'JSD-309', id=u'317281'>] 

你會看到告訴你JQL可以在你的請求中輸出。應該給你一個關於如何解決問題的想法。

這是Python 2.7.5JIRA 6.2但是我也試過Jira 6.0.7它工作。

此外,您可以嘗試將您的JQL調整爲完整的項目名稱而不是密鑰,如果它包含空格將其包含在引號中。

+0

是的它看起來像你的例子,但列表仍然是空的。你回來的問題列表在哪裏?我嘗試過所有的東西,雙引號,單引號,轉義引號,大寫,小寫,混合。永遠不會得到任何回報 – user3335101

+0

我用它進行了更新,打印輸出。這是否僅僅發生在你本地的實例上,或者如果你嘗試像我一樣擊中Atlassians JIRA,它也會發生嗎? – Welsh

+0

它只發生在我的Jira實例上,如同你的例子一樣,對Atlassians工作正常。 – user3335101

1

你做jira = JIRA(options, basic_auth = ('user', password')),但你有沒有在其他地方定義的選項?你叫JIRA = JIRA(之前你的選項應該定義服務器.....等等,像這樣:

options { 'server' : 'http://jira.atlassian.com' } 

,然後你的電話應該是這樣的:

jira = JIRA(options = options, basic_auth = ('user', 'password')) 

除非已完成已,我建議你做到這一點,看看它是否工作如果沒有,嘗試拼寫巨人它在JIRA拼寫完全相同的方式

0

例:

projects = jira.projects() 
keys = sorted([project.key for project in projects]) 
for key_val in keys: 
    issues = jira.search_issues('project='+key_val,maxResults=500000) 
    for issue_names in issues: 
     print 'issue id - ',issue_names