Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a ticket with an attachment on Sourceforge

I am trying to create a ticket with an attachment on a Sourceforge-based issue tracker. Sourceforge uses Apache Allura.

According to Sourceforge's documentation, a ticket has the following structure:

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

I wrote a small Python script using requests to create a ticket, but I have not been able to figure out how to include an attachment.

Snippet for creating a ticket without an attachment:

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)

Allura's source contains sample code for creating a ticket with an attachment, but I did not understand how to translate that POST request into something requests could use.

How can I create a ticket with an attachment on Sourceforge using requests?

like image 696
Moshe Avatar asked Apr 28 '26 20:04

Moshe


1 Answers

Snippet for creating a ticket with an attachment:

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)
like image 194
Moshe Avatar answered Apr 30 '26 10:04

Moshe