Pergunta

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)...

Foi útil?

Solução

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'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top