0

I'm having troubles on retrieving data on posting a request:

curl 'http://127.0.0.1:8005/api/curricula_report/v1/report-data/?format=json' --data-binary '{"storesIds":[80403,66729,66996,67355,67393,67405,67406,67417,67439,67690,67713,67780,67851,68060,68082,68224,68305,68338,68414,68422,68437,68508,68513,68542,69004,69131,69516,69693,69845,69886,69887,69890,69954,69960,69976,70025,70102,70151,70166,70273,70334,70493,70512,70632,70696,70864,70991,71099,71415,71551,71572,71693,71926,71979,72478,72830,72846,72848,72872,72881,73202,73253,73326,73337,73363,73364,73382,73452,73463,73674,73683,73776,78997,73909,74666,73921,73989,77485,77538,77843,78135,77902,77833,78961,79238,80106,79239,79785,80914,81129,80800,81115,80520,80521,80801,81825,81659,82441,83128,74489],"courseIds":["3f8c8bd7-5aae-4184-a824-68edf528a011"],"audienceId":2,"hiredId":1,"user":"TW9oYW1tYWQ7UmhhbWFuO21vaGFtbWFkcmhhbWFuO21vaGFtbWFkcmhhbWFuO21vaGFtbWFkQGRla2tncm91cC5jb207ZHVua2luYnJhbmRzOzIwMTgtMDctMDNUMTE6MjE6MzhaO0M3RDVCMUZEOUExN0RFNDEyNUVDODJBRTEzOTFEQ0E5N0M4Q0VFNUM"}' --compressed 

on inspecting the request through ipdb:

def post(self, request, *args, **kwargs):
    post_data_dict = request.data
    user_token = post_data_dict.get('user', None)

user is always None.

ipdb> post_data_dict
<QueryDict: {u'{"storesIds":[80403,66729,66996,67355,67393,67405,67406,67417,67439,67690,67713,67780,67851,68060,68082,68224,68305,68338,68414,68422,68437,68508,68513,68542,69004,69131,69516,69693,69845,69886,69887,69890,69954,69960,69976,70025,70102,70151,70166,70273,70334,70493,70512,70632,70696,70864,70991,71099,71415,71551,71572,71693,71926,71979,72478,72830,72846,72848,72872,72881,73202,73253,73326,73337,73363,73364,73382,73452,73463,73674,73683,73776,78997,73909,74666,73921,73989,77485,77538,77843,78135,77902,77833,78961,79238,80106,79239,79785,80914,81129,80800,81115,80520,80521,80801,81825,81659,82441,83128,74489],"courseIds":["3f8c8bd7-5aae-4184-a824-68edf528a011"],"audienceId":2,"hiredId":1,"user":"TW9oYW1tYWQ7UmhhbWFuO21vaGFtbWFkcmhhbWFuO21vaGFtbWFkcmhhbWFuO21vaGFtbWFkQGRla2tncm91cC5jb207ZHVua2luYnJhbmRzOzIwMTgtMDctMDNUMTE6MjE6MzhaO0M3RDVCMUZEOUExN0RFNDEyNUVDODJBRTEzOTFEQ0E5N0M4Q0VFNUM"}': [u'']}>

not sure what I'm doing wrong, all the keys seems to be omitted, and the values too:

ipdb> post_data_dict.keys()
[u'{"storesIds":[80403,66729,66996,67355,67393,67405,67406,67417,67439,67690,67713,67780,67851,68060,68082,68224,68305,68338,68414,68422,68437,68508,68513,68542,69004,69131,69516,69693,69845,69886,69887,69890,69954,69960,69976,70025,70102,70151,70166,70273,70334,70493,70512,70632,70696,70864,70991,71099,71415,71551,71572,71693,71926,71979,72478,72830,72846,72848,72872,72881,73202,73253,73326,73337,73363,73364,73382,73452,73463,73674,73683,73776,78997,73909,74666,73921,73989,77485,77538,77843,78135,77902,77833,78961,79238,80106,79239,79785,80914,81129,80800,81115,80520,80521,80801,81825,81659,82441,83128,74489],"courseIds":["3f8c8bd7-5aae-4184-a824-68edf528a011"],"audienceId":2,"hiredId":1,"user":"TW9oYW1tYWQ7UmhhbWFuO21vaGFtbWFkcmhhbWFuO21vaGFtbWFkcmhhbWFuO21vaGFtbWFkQGRla2tncm91cC5jb207ZHVua2luYnJhbmRzOzIwMTgtMDctMDNUMTE6MjE6MzhaO0M3RDVCMUZEOUExN0RFNDEyNUVDODJBRTEzOTFEQ0E5N0M4Q0VFNUM"}']
ipdb> post_data_dict.values()
[u'']

with rest_framework v 3.1.3 it was working.

any help on this?

Luke
  • 1,794
  • 10
  • 43
  • 70
  • 1
    I think the problem is with your curl command. Try setting the header: https://stackoverflow.com/questions/7172784/how-to-post-json-data-with-curl-from-terminal-commandline-to-test-spring-rest – munsu Sep 05 '18 at 02:12
  • @Luke Did you try to post using POSTMAN tool? – JPG Sep 05 '18 at 04:09

1 Answers1

0

I had similar issue few weeks ago.

The problem is with the content-type of the request which in your case is application/x-www-form-urlencoded

This for some reason causing the problem which you experience.

If you explicitly set the content type of your request to application/json, the input is processed as you'd expect:

curl  -H "Content-Type: application/json"  ....
Enthusiast Martin
  • 3,041
  • 2
  • 12
  • 20