Note that there are some explanatory texts on larger screens.

plurals
  1. POPUT request to django tastypie resource not working
    primarykey
    data
    text
    <p>i'm trying to do a put request to my django tastypie resource in order to update user info. Up to now, i can make post request but put is not working.</p> <p>In my api.py i have this:</p> <pre><code>class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name = 'auth/user' fields = ['username', 'email'] authentication = BasicAuthentication() authorization = DjangoAuthorization() filtering = { "username": ('exact',), } class UserSignUpResource(ModelResource): class Meta: object_class = User resource_name = 'register_user' fields = ['username', 'email' , 'password'] allowed_methods = ['put','post'] authentication = BasicAuthentication() authorization = DjangoAuthorization() queryset = User.objects.all() def obj_create(self, bundle, request=None, **kwargs): bundle = super(UserSignUpResource, self).obj_create(bundle) </code></pre> <p>And to test i'me using this:</p> <pre><code>import urllib2, json def post(): def basic_authorization(user, password): s = user + ":" + password return "Basic " + s.encode("base64").rstrip() data = json.dumps({'username':'david_000', 'email':'davidupdat@gmail.com', 'password':'xxx','provider':'twitter','extra_data':{'access_token':'xxx','id':'xxx'}}) req = urllib2.Request("http://192.168.1.114:8080/api/stats/register_user/", headers = {"Authorization": basic_authorization("xxx","xxx"),"Content-Type": "application/json"}, data = data) req.get_method = lambda:'PUT' f = urllib2.urlopen(req) post() </code></pre> <p>I'm getting this error:</p> <pre><code>Traceback (most recent call last): File "test.py", line 18, in &lt;module&gt; post() File "test.py", line 16, in post f = urllib2.urlopen(req) File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 406, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 519, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 444, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 400: BAD REQUEST </code></pre> <p>UPDATE:</p> <p>i try this, but it gives me the same error:</p> <pre><code>def obj_update(self, bundle, request=None, **kwargs): bundle = super(UserSignUpResource, self).obj_update(bundle) </code></pre> <p>Any idea? Thanks in Advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload