Вопрос

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