Reputation: 181290
I want to read a raw HTTP request in Django 1.3.
Is there an easy way to do it?
I tried the following without success:
clength = int(request.META.get("CONTENT_LENGTH"))
data = request.read(1000)
# data comes out empty
Also tried:
for part in request:
pass
# never enters the loop
The reason I am doing this is because somehow my raw_post_data
attribute is empty when using multipart/related
MIME information on the POST
command. Apparently is a bug that's been there for a long time.
Upvotes: 6
Views: 4049
Reputation: 310
For django version < 1.4, you can use HttpRequest.raw_post_data
, and for version >= 1.4, using HttpRequest.body
instead.
Upvotes: 3
Reputation: 5455
Have you tried HttpRequest.raw_post_data? Looks like something you should take a look at until the bug is fixed. https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.raw_post_data
Upvotes: 2