tuomur / python-odata

A simple library for read/write access to OData services
MIT License
79 stars 59 forks source link

Support custom http headers #25

Closed nicenemo closed 5 years ago

nicenemo commented 6 years ago

Pardon my Python, I am a Java programmer.

I changed your code in my fork to support custom http headers. As far as I understand your version does not support it.

Custom http headers: https://github.com/nicenemo/python-odata/commit/8037ed59f1aa5aad90503bc4a6ad2908dab4b661

tpow commented 5 years ago

Custom headers probably are not needed in python-odata because the underlying requests library already supports them. You can add default custom headers as necessary by setting up a session object and then passing it to the ODataService.

Using a session is demonstrated in the python-odata documentation in Connecting to an Endpoint using NTLM Auth: https://tuomur-python-odata.readthedocs.io/en/latest/service.html

See the documentation for Sessions in the requests library: http://docs.python-requests.org/en/master/user/advanced/#session-objects

Setting it up would look something like this:

import requests
my_session = requests.Session()
my_session.auth = ('user', 'pass')
my_session.headers.update({'x-test': 'true'})
my_session.get('basic url')  # Test it, should return 200 OK
Service = ODataService('url', session=my_session)