2016-02-12 39 views
3

我正在嘗試在基於Sourceforge的問題跟蹤器上創建附件的票證。 Sourceforge使用Apache Allura。在Sourceforge上創建帶附件的票據

根據Sourceforge's documentation,一票具有以下結構:

POST request to: /p/{project}/{tracker}/new 

ticket_form.summary - ticket title 
ticket_form.description - ticket description 
ticket_form.status - ticket status 
ticket_form.assigned_to - username of ticket assignee 
ticket_form.labels - comma-separated list of ticket labels 
ticket_form.attachment - (optional) attachment 

我寫了使用requests創建票證小Python腳本,但我一直無法弄清楚如何包括附件。

片段對於沒有附件創建票:

import requests 

action = "https://sourceforge.net/rest/p/test-sourceforge-api/tickets/new" 

url = action + "?access_token=" + token 

body = {'access_token':token, 
    'ticket_form.description': "Test Description", 
    'ticket_form.summary':'Test Title' 
    } 

r = requests.post(url, data=body) 

誘惑的source包含示例代碼創建帶有附件的票,但我不知道如何把這種POST請求到的東西requests可以使用。

如何使用requests在Sourceforge上創建附件的附件?

回答

1

片段用於與附件創建票:

import requests 

action = "https://sourceforge.net/rest/p/test-sourceforge-api/tickets/new" 

url = action + "?access_token=" + token 

body = {'access_token':token, 
    'ticket_form.description': "Test Description", 
    'ticket_form.summary':'Test Title' 
    } 

files={'ticket_form.attachment':("myfilename","myfilecontents", 'application/octet-stream')} 

r = requests.post(url, data=body, files=files)