I'm trying to send data to my Django-powered server using Tastypie.
I have this model
class Open(models.Model):
name=models.TextField()
and this URLconf
open_resource=OpenResource()
urlpatterns = patterns('',
url(r'^api/', include(open_resource.urls)),
url(r'^admin/', include(admin.site.urls)),
)
when I run the tastypie curl command
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"name","awdawd"}' http://localhost:8000/api/open/
I get the error
HTTP/1.0 400 BAD REQUEST
Date: Sat, 05 Apr 2014 12:18:48 GMT
Server: WSGIServer/0.1 Python/2.7.3
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
{"error": ""}
I've tried everything and can't seem to get this working.
Does anyone have a clue on this one?
Thanks a lot in advance
I get this unhelpful error whenever I provide invalid JSON data.
Correct JSON format is:
{"foo": "bar"} // correct!
[{"foo": "bar"}, {"fiz": "baz"}] // correct!
{"foo": "bar", "fiz": "baz"} // correct!
Examples of common mistakes:
{'foo': 'bar'} // error is using single quotes instead of double quotes
{foo: "bar"} // error is not using double quotes for "foo"
{"foo", "bar"} // error is using a comma (,) instead of a colon (:) ← Your error
Examples of more complex mistakes:
[{"foo": "bar"}, {"fiz": "baz"},]
// error is using a comma at the end of a list or array
{"foo": "bar", "fiz": "baz",} // courtesy @gthmb
// error is using a comma at the end of the final key-value pair
Think your JSON is valid? Double-check with a JSON validator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With