request.body returns an empty string. Here is a copy of my request

*******************************
<WSGIRequest
path:/blog/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{'csrftoken': 'ivBhSl6RT0TXdrIrTR9WxGeLwyXmpygN'},
META:{'CCACHE_HASHDIR': '',
 'COLORTERM': 'gnome-terminal',
 'CONTENT_LENGTH': '0',
 'CONTENT_TYPE': 'application/json',
 'CVS_RSH': 'ssh',
 'DBUS_SESSION_BUS_ADDRESS': 
'unix:abstract=/tmp/dbus-FukIqsBHiS,guid=2bc53020b746b1753871d45a51ce0be2',
 'DESKTOP_SESSION': 'gnome',
 'DISPLAY': ':0',
 'DJANGO_SETTINGS_MODULE': 'testviews.settings',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'GDMSESSION': 'gnome',
 'GJS_DEBUG_OUTPUT': 'stderr',
 'GJS_DEBUG_TOPICS': 'JS ERROR;JS LOG',
 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated',
 'GNOME_KEYRING_CONTROL': '/run/user/1000/keyring-wmgVNG',
 'GNOME_KEYRING_PID': '1262',
 'GPG_AGENT_INFO': '/run/user/1000/keyring-wmgVNG/gpg:0:1',
 'HISTCONTROL': 'ignoredups',
 'HISTSIZE': '1000',
 'HOME': '/home/lucas',
 'HOSTNAME': 'localhost.localdomain',
 'HTTP_ACCEPT': '*/*',
 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
 'HTTP_CONNECTION': 'keep-alive',
 'HTTP_COOKIE': 'csrftoken=ivBhSl6RT0TXdrIrTR9WxGeLwyXmpygN',
 'HTTP_HELLO': 'world',
 'HTTP_HOST': '127.0.0.1:8000',
 'HTTP_ORIGIN': 'chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36',
 'HTTP_WHAT': 'asdf',
 'IMSETTINGS_INTEGRATE_DESKTOP': 'yes',
 'IMSETTINGS_MODULE': 'none',
 'KRB5CCNAME': 'DIR:/run/user/1000/krb5cc_a3b7d843fdc5b71dcc827ae551ce0bd1',
 'LANG': 'en_US.UTF-8',
 'LESSOPEN': '||/usr/bin/lesspipe.sh %s',
 'LOGNAME': 'lucas',
 'LS_COLORS': 
'rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lz=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.bz=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:',
 'MAIL': '/var/spool/mail/lucas',
 'OLDPWD': '/home/lucas/Programming/Python/Django/TestViews/testviews/blog',
 'PATH': 
'/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/lucas/.local/bin:/home/lucas/bin',
 'PATH_INFO': u'/blog/',
 'PWD': '/home/lucas/Programming/Python/Django/TestViews/testviews',
 'QTDIR': '/usr/lib64/qt-3.3',
 'QTINC': '/usr/lib64/qt-3.3/include',
 'QTLIB': '/usr/lib64/qt-3.3/lib',
 'QT_GRAPHICSSYSTEM_CHECKED': '1',
 'QT_IM_MODULE': 'ibus',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '127.0.0.1',
 'REMOTE_HOST': '',
 'REQUEST_METHOD': 'POST',
 'RUN_MAIN': 'true',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': 'localhost.localdomain',
 'SERVER_PORT': '8000',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.7.3',
 'SESSION_MANAGER': 
'local/unix:@/tmp/.ICE-unix/1264,unix/unix:/tmp/.ICE-unix/1264',
 'SHELL': '/bin/bash',
 'SHLVL': '2',
 'SSH_AUTH_SOCK': '/run/user/1000/keyring-wmgVNG/ssh',
 'TERM': 'xterm-256color',
 'TZ': 'America/Denver',
 'USER': 'lucas',
 'USERNAME': 'lucas',
 'WINDOWID': '35702123',
 'WINDOWPATH': '1',
 'XAUTHORITY': '/var/run/gdm/auth-for-lucas-jI22V1/database',
 'XDG_MENU_PREFIX': 'gnome-',
 'XDG_RUNTIME_DIR': '/run/user/1000',
 'XDG_SEAT': 'seat0',
 'XDG_SESSION_ID': '2',
 'XDG_VTNR': '1',
 'XMODIFIERS': '@im=ibus',
 '_': '/usr/bin/python',
 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7ffe45b97270>,
 'wsgi.file_wrapper': <class wsgiref.util.FileWrapper at 0x1371120>,
 'wsgi.input': <socket._fileobject object at 0x7ffe3425ac50>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': True,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>


On Tuesday, July 2, 2013 3:34:47 PM UTC-6, Nikolas Stevenson-Molnar wrote:
>
>  Are you sending the JSON document as the body of your POST request? If 
> so, you won't see anything in request.POST, because it's only populated for 
> requests using application/x-www-form-urlencoded. You probably want to use 
> request.body (
> https://docs.djangoproject.com/en/1.5/ref/request-response/#django.http.HttpRequest.body)
>  
> to get at the raw JSON. To get it as a dictionary object in Python, import 
> the json module, then do:
>
> >>> data = json.loads(request.body)
>
> _Nik
>
> On 7/2/2013 2:28 PM, Lucas Simon wrote:
>  
> How does this fit in with a large JSON document? There should be a way to 
> parse all of this arbitrary data, and filter out the stuff that fits into a 
> form
>
> On Tuesday, July 2, 2013 3:08:10 PM UTC-6, Nikolas Stevenson-Molnar wrote: 
>>
>>  That's the expected output, since your URL pattern to that view doesn't 
>> contain any arguments. Take a look at the examples in 
>> https://docs.djangoproject.com/en/1.5/topics/http/urls/ ... the URL 
>> patterns with groups will have the matched values passed to the view 
>> function as arguments (named groups are passed as kwargs).
>>
>> Likewise, unless you submitted POST data with your request, you should 
>> expect request.POST to be empty.
>>
>> _Nik
>>
>> On 7/2/2013 2:03 PM, Lucas Simon wrote:
>>  
>> Hi, 
>>
>>  I think I found a bug and was not sure where to post it other than 
>> here. I have created a view defined as follows
>>
>>  from django.http import HttpResponse, Http404
>> from django.views.generic.base import View
>>
>>  class TestView(View):
>>  def post(self, request, *args, **kwargs):
>>  print "*******************************"
>>  print request.POST
>>  print args
>>  print kwargs
>>  print "*******************************"
>>  return HttpResponse("hello, world")
>>  
>>  When I make a post request with CURL or advanced rest framework, the 
>> console outputs blank data,
>>
>>  *******************************
>> <QueryDict: {}>
>> ()
>> {}
>> *******************************
>> [02/Jul/2013 15:00:39] "POST /blog/ HTTP/1.1" 200 12
>>
>>  Also, it is probably worth mentioning that I commented out the csrf 
>> middleware. My two urls.py files are define as
>>
>>  from django.conf.urls import patterns, include, url
>>
>>  # Uncomment the next two lines to enable the admin:
>> # from django.contrib import admin
>> # admin.autodiscover()
>>
>>  urlpatterns = patterns('',
>>  url(r'^blog/', include('blog.urls')),
>>     # Uncomment the admin/doc line below to enable admin documentation:
>>     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>>
>>      # Uncomment the next line to enable the admin:
>>     # url(r'^admin/', include(admin.site.urls)),
>> )
>>  
>>  and as follows for blog.urls.py
>>
>>  from django.conf.urls import patterns, include, url
>> from .views import * 
>>
>>  urlpatterns = patterns('',
>>     url(r'^$', TestView.as_view()),
>> )
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>>
>>  -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com <javascript:>.
> To post to this group, send email to django...@googlegroups.com<javascript:>
> .
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
>
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to