Adding headers to requests module

后端 未结 2 925
滥情空心
滥情空心 2020-11-27 14:46

Earlier I used httplib module to add a header in the request. Now I am trying the same thing with the requests module.

This is the python re

2条回答
  •  有刺的猬
    2020-11-27 15:32

    You can also do this to set a header for all future gets for the Session object, where x-test will be in all s.get() calls:

    s = requests.Session()
    s.auth = ('user', 'pass')
    s.headers.update({'x-test': 'true'})
    
    # both 'x-test' and 'x-test2' are sent
    s.get('http://httpbin.org/headers', headers={'x-test2': 'true'})
    

    from: http://docs.python-requests.org/en/latest/user/advanced/#session-objects

提交回复
热议问题