我正在尝试在基于Sourceforge的问题跟踪器上创建带附件的票证。 Sourceforge使用Apache Allura。
根据Sourceforge's documentation,票证具有以下结构:
var express = require('express'),
request = require('request'),
path = require('path'),
fs = require('fs'),
bodyParser = require("body-parser");
var Twitter = require("node-twitter-api");
var app = express();
...
var twitter = new Twitter({
consumerKey: 'XXXXXXX',
consumerSecret: 'XXXXXX',
callback: 'http://thelionstestingjungle.com'});
var _requestSecret;
app.get("/tokenRequest", function(req, res) {
console.log('Token request');
twitter.getRequestToken(function(err, requestToken, requestSecret) {
if (err) {
console.log('Token request error');
res.status(500).send(err);
} else {
console.log('Request secret: ' + requestSecret);
_requestSecret = requestSecret;
res.redirect("https://api.twitter.com/oauth/authenticate?oauth_token=" + requestToken);
}
});});
app.get("/accessToken", function(req, res) {
console.log('Access token');
var requestToken = req.query.oauth_token,
verifier = req.query.oauth_verifier;
twitter.getAccessToken(requestToken, _requestSecret, verifier, function(err, accessToken, accessSecret) {
if (err) {
console.log('Get info error');
res.status(500).send(err);
} else {
twitter.verifyCredentials(accessToken, accessSecret, function(err, user) {
if (err) {
console.log('Verification in get info error');
res.status(500).send(err);
} else {
console.log('User: ' + JSON.stringify(user));
res.send(user);
}
});
}
});});
...
我使用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
编写了一个小的Python脚本来创建一个票证,但我无法弄清楚如何包含附件。
用于创建没有附件的故障单的代码段:
requests
Allura的source包含用于创建带附件的故障单的示例代码,但我不明白如何将该POST请求转换为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)
可以使用的内容。
如何使用requests
?
答案 0 :(得分: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)