質問

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