python请求可以在每个会话或全局挂钩中有挂钩吗?

时间:2015-01-16 08:37:26

标签: python hook python-requests portforwarding

我计划使用https://github.com/shellycloud/forwardmachine

我想使用请求联系那些转发的服务器 我想过使用请求挂钩,但我不想在每个请求中传递它们。

我想要像这样的全球/会话:

import requests

def forwarder_pre_request_hook(req, *args, **args):
   # do the trick I want, and replace the hostname and port of the url
   # I would still need to figure howto do it.
   return req

# globally 
requests.hooks = dict(pre_request=forwarder_pre_request_hook)

# per session
requests.Session(hooks=dict(pre_request=forwarder_pre_request_hook))

有可能吗?

0 个答案:

没有答案