Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Feature: Additional request headers #10

wants to merge 6 commits into


None yet
2 participants

dejw commented Jul 14, 2011

Hello Josh,

I have just implemented tiny change, which allows to specify additional request headers to be sent. Feature also provides convenient context manager for specifying request headers for certain method invocations.

This feature actually resolves the #7 issue, and can be useful when e.g. remote service requires some additional (custom) headers required in authentication process (my actual motivation to implementing this feature).

I have bumped version number to 0.1.4. It is in separate commit so You can easily drop this if You will.

Tests are included of course.

Best regards,

zeph commented May 23, 2012

hi, can we this change in? would be pretty useful for me too

zeph commented May 23, 2012

uhmm... ur patch doesn't seem to solve my problem

(jsonrpc)dyn-86-client:scripts zeph$ pip install ../../dejw-jsonrpclib
Unpacking /Users/zeph/tmp/dejw-jsonrpclib
  Running setup.py egg_info for package from file:///Users/zeph/tmp/dejw-jsonrpclib
Installing collected packages: jsonrpclib
  Running setup.py install for jsonrpclib
Successfully installed jsonrpclib
Cleaning up...

(jsonrpc)dyn-86-client:scripts zeph$ python changelog2confluence.py 
Traceback (most recent call last):
  File "changelog2confluence.py", line 9, in <module>
    print c.getSpace(["DOC"])
  File "/Users/zeph/tmp/virt_env/jsonrpc/lib/python2.6/site-packages/jsonrpclib/jsonrpc.py", line 322, in __call__
    return self.__send(self.__name, args)
  File "/Users/zeph/tmp/virt_env/jsonrpc/lib/python2.6/site-packages/jsonrpclib/jsonrpc.py", line 258, in _request
  File "/Users/zeph/tmp/virt_env/jsonrpc/lib/python2.6/site-packages/jsonrpclib/jsonrpc.py", line 577, in check_for_errors
    raise ProtocolError((code, message))
jsonrpclib.jsonrpc.ProtocolError: (-32600, u'JSON-RPC requests must have the Content-type: application/json')

(jsonrpc)dyn-86-client:scripts zeph$ find ~/tmp/jsonrpclib/jsonrpclib/|xargs grep headers
/Users/zeph/tmp/jsonrpclib/jsonrpclib//jsonrpc.py:        connection.endheaders()
/Users/zeph/tmp/jsonrpclib/jsonrpclib//jsonrpc.py:            host, extra_headers, x509 = self.get_host_info(host)
/Users/zeph/tmp/jsonrpclib/jsonrpclib//SimpleJSONRPCServer.py:            size_remaining = int(self.headers["content-length"])
/Users/zeph/tmp/jsonrpclib/jsonrpclib//SimpleJSONRPCServer.py:        self.end_headers()

are u overriding the headers or just adding them? this is my code...

#!/usr/bin/env python

CONFLUENCE = "https://confluence.<COMPANY>.com/rpc/json-rpc/confluenceservice-v2"
# https://developer.atlassian.com/display/CONFDEV/Confluence+JSON-RPC+APIs

import jsonrpclib
c = jsonrpclib.Server(CONFLUENCE, headers={'Content-type': 'application/json'})

print c.getSpace(["DOC"])

zeph commented May 23, 2012

k, u are not overriding... feel free to pull my change

if of any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment