Unable to set headers on github.post method
rhlobo opened this issue · comments
I have been trying to set a hook for my organization, and because the related API methods are still in alpha, an 'Accept' header is needed.
When I:
hook_registration = {
'name': 'web',
'active': True,
'events': ['push', 'pull_request'],
'config': {
'url': 'http://example.com/webhook',
'content_type': 'json'
}
}
return github.post('/orgs/%s/hooks' % org,
data=hook_registration,
headers={'Accept': 'application/vnd.github.sersi-preview+json'})
I get an error:
...
File "/home/rhlobo/.virtualenvs/jackdaw/lib/python2.7/site-packages/flask_github.py", line 191, in post
data=data, **kwargs)
TypeError: request() got multiple values for keyword argument 'headers'
You can install the new version via pip.
pip install -U github-flask
Thanks, I appreciate the fast response =)
That problem is fixed, but I still cannot complete the request successfully.
Github now complains about problems parsing the json
, returning status code 400.
When I try to make the exact same request through requests
it works, tough:
import requests
hook_registration = {
'name': 'web',
'active': True,
'events': ['push'],
'config': {
'url': 'https://webhooks.chaordicsystems.com/hooks/push_and_pr',
'content_type': 'json'
}
}
# access_token is not the real one for obvious reasons...
requests.post('https://api.github.com/orgs/%s/hooks?access_token=e892xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx61e4cb' % org,
data=json.dumps(hook_registration),
headers={'Accept': 'application/vnd.github.sersi-preview+json'})
# Works!!! Returns 201
github.post('orgs/%s/hooks' % org,
data=json.dumps(hook_registration),
headers={'Accept': 'application/vnd.github.sersi-preview+json'})
# Failure: 400 =(
(Sorry if you preferred if I opened another issue instead of continuing this one)
I did not have the time to see your code, but if some is left tomorrow I will make a pull request... Cheers
Sorry for late reply. I can't reproduce the problem myself because I don't have access to an organization to add a hook. Did you make it work or still have the problem?