문제

From looking at their source it appears that the method member attribute is what I want.

https://github.com/kennethreitz/requests/blob/master/requests/models.py

To summarise by example, this is what I want:

>>> r = requests.get("http://httpbin.org/get")
>>> print r.method
'GET'

However I can't figure out if there's a way to get it (without writing my own hacky wrapper)...

도움이 되었습니까?

해결책

It's stored in the request attribute of the response:

>>> r = requests.head('http://www.example.com')
>>> r.request.method
'HEAD'

>>> r = requests.get('http://www.example.com')
>>> r.request.method
'GET'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top