如何从Python Requests的'Response'对象中获取HTTP动词?
从他们的源代码来看,method
这个成员属性正是我想要的东西。
https://github.com/kennethreitz/requests/blob/master/requests/models.py
简单来说,通过一个例子,这就是我想要的:
>>> r = requests.get("http://httpbin.org/get")
>>> print r.method
'GET'
不过我还没搞清楚有没有办法获取它(不想自己写个麻烦的包装器)……
1 个回答
3
它被存储在响应的 request
属性中:
>>> r = requests.head('http://www.example.com')
>>> r.request.method
'HEAD'
>>> r = requests.get('http://www.example.com')
>>> r.request.method
'GET'