Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a raw HTTP request in Django 1.3

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.

like image 606
Pablo Santa Cruz Avatar asked Oct 28 '11 16:10

Pablo Santa Cruz


2 Answers

For django version < 1.4, you can use HttpRequest.raw_post_data, and for version >= 1.4, using HttpRequest.body instead.

like image 195
nevesly Avatar answered Oct 20 '22 11:10

nevesly


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

like image 35
xeor Avatar answered Oct 20 '22 09:10

xeor