python flask oauth_Flask OAuth Github POST请求

我正在bakery项目中使用Flask(想法类似于travisci,但是用python完成的)。以及为拥有授权github用户的存储库创建添加webhook的模块。我没有在这里粘贴完整的示例代码,这里是我要做的事情的片段。完整示例可在separate gist中找到。在

问题是Github API GET请求正常工作。但同时返回responce体中的401和{}。在# this method is working

@app.route('/repos')

def repos():

# only logged in user should call it, but I skip it in this example

resp = github.get('/user/repos', data = {'type': 'public'})

# responce status code is ok, and data is returned

print(resp.data) # should print to console

@app.route('/addhook/')

def repos(full_name):

HOOK_URL = 'http://example.com/hook'

resp = github.post('/repos/%(full_name)s/hooks' % {'full_name': full_name},

data = {

'name':'web',

'active': True,

'events': ['push'],

'config': {

'url': HOOK_URL,

'content_type': 'json'

}

},

format = 'json'

)

# POST request is not working and form request that Github is not understand

print(resp.status, resp.data)

我检查了哪些header generate Flask OAuth,发现它添加了额外的标题行,其中包含以下内容(跳过实际值):

^{pr2}$

结果Github返回这个状态,可能不知道该怎么处理。我找到了解决方法,如果我只复制token并直接调用Github API,就可以得到预期的结果。这里的等价叫法是curl:$ curl https://api.github.com/repos/xen/league-gothic/hooks?access_token=XXX -X POST --data '{"name":"web","active":true,"events": ["push"],"config": {"url": "http://example.com/hook","content_type": "json"}}'

所以,问题是:有没有可能让它看起来更好,并使用flaskoauth方法POST来简化代码并使其正常工作?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值