Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble GETting a viewconf I've POSTed #10

Closed
mccalluc opened this issue Feb 13, 2017 · 2 comments
Closed

Trouble GETting a viewconf I've POSTed #10

mccalluc opened this issue Feb 13, 2017 · 2 comments

Comments

@mccalluc
Copy link
Collaborator

mccalluc commented Feb 13, 2017

On the 0.0.7 Docker image: (or from source: I just replicated it)

$ curl --form 'fileupload={"foo":"bar"}' http://localhost:8888/api/v1/viewconfs/
{"uid": "WsQUwinvSe2LE09eRi0vxA"}

$ curl http://localhost:8888/api/v1/viewconfs/?d=WsQUwinvSe2LE09eRi0vxA
<h1>Server Error (500)</h1>
  • Should it require username and password?
  • Could the ID be set on the post? Would make it a little bit easier to script, rather than parsing the JSON? But it's reasonable not to offer that, too.
  • Why doesn't the GET work?

POST causes no error in the log, but on the GET:

[13/Feb/2017 21:08:17] ERROR [django.request:124] Internal Server Error: /api/v1/viewconfs/
Traceback (most recent call last):
  File "/opt/conda/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/opt/conda/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/opt/conda/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/conda/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/opt/conda/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/conda/lib/python2.7/site-packages/rest_framework/views.py", line 477, in dispatch
    response = self.handle_exception(exc)
  File "/opt/conda/lib/python2.7/site-packages/rest_framework/views.py", line 437, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/conda/lib/python2.7/site-packages/rest_framework/views.py", line 474, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/conda/lib/python2.7/site-packages/rest_framework/decorators.py", line 52, in handler
    return func(*args, **kwargs)
  File "./tilesets/views.py", line 254, in viewconfs
    return JsonResponse(json.loads(obj.viewconf))
  File "/opt/conda/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/opt/conda/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/conda/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Maybe it's not actually writing to the database?

@mccalluc
Copy link
Collaborator Author

It looks like the whole POST is being stored in the database, and it's having trouble parsing it as json:

--------------------------5de6d8535ce81884
Content-Disposition: form-data; name="fileupload"

{"foo":"bar"}
--------------------------5de6d8535ce81884--

(This is tested, but not at the HTTP level, and I guess it hasn't been used up till now.)

@mccalluc
Copy link
Collaborator Author

Nils suggested this:

$ curl -H "Content-Type: application/json" -X POST -d '{"foo":"bar"}' http://localhost:8001/api/v1/viewconfs/
...
$ curl http://localhost:8001/api/v1/viewconfs/?d=UIv5l2H2RBiIRAWT5xlVmA
{"foo": "bar"}

So I'm not blocked, but validation at the time of the POST might have saved some trouble?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants