python - Requests body empty -
why following print none?
import requests r = requests.request('http://cnn.com', data={"foo":"bar"}) print r.request.body # none if change cnn.com www.cnn.com, prints proper body. noticed redirect (there 301 in r.history). what's going on?
your code stands doesn't work—it'll raise typeerror right off bat. think can guess @ you're trying do.
if change request post, indeed return none.
why? because you're asking body of redirect, not body of original request. that, want r.history[0].request.body.
read redirection , history more info. note auto-redirecting isn't documented work post requests, though anyway. note in earlier versions of requests, history entries didn't have complete request objects. (you'll have @ version history if need know when changed. seems there in 1.2.0, , not in 0.14.2—and lot of things added or changes in 1.0.0 aren't documented, because major rewrite.)
as side note… why need this? if need know body sent, why not two-step process of creating request , sending it, can see body beforehand? (or, matter, encode data explicitly?)
Comments
Post a Comment