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

JSON decode Error for test_remote_project demo #59

Closed
domguard opened this issue Nov 7, 2012 · 9 comments
Closed

JSON decode Error for test_remote_project demo #59

domguard opened this issue Nov 7, 2012 · 9 comments

Comments

@domguard
Copy link

domguard commented Nov 7, 2012

Perhaps this is linked to the fact I'm using python 2.6 :

[07/Nov/2012 02:16:50] "GET /cities_light/city/?q=res&limit=20&format=json HTTP/1.0" 404 2222
Internal Server Error: /autocomplete/CityRestAutocomplete/
Traceback (most recent call last):
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/django/views/generic/base.py", line 48, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/django/views/generic/base.py", line 69, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/autocomplete_light/views.py", line 52, in get
    return http.HttpResponse(autocomplete.autocomplete_html())
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/autocomplete_light/autocomplete/base.py", line 94, in autocomplete_html
    for choice in self.choices_for_request():
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/autocomplete_light/autocomplete/rest_model.py", line 71, in choices_for_request
    for choice in self.get_remote_choices(slots):
  File "/home/dom/.virtualenvs/acl/lib/python2.6/site-packages/autocomplete_light/autocomplete/rest_model.py", line 96, in get_remote_choices
    for data in simplejson.loads(body):
  File "/usr/lib/python2.6/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.6/json/decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.6/json/decoder.py", line 338, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
@jpic
Copy link
Member

jpic commented Nov 7, 2012

I just tried on a fresh install and I see no problem on these urls:

I'm sorry but I have no python 2.6 install anywhere ...

What did you do exactly to get this stacktrace ?

@domguard
Copy link
Author

domguard commented Nov 7, 2012

Switched to a python 2.7 just in case, still got this error
The two URLS you provided are working, but when i'm using the test_remote_project, and trying to use the autocomplete in the admin, the URLS are not the same, they're like :

http://localhost:8000/autocomplete/CityRestAutocomplete/?q=res

@jpic
Copy link
Member

jpic commented Nov 7, 2012

Can you please explain step by step how you get the error please ?

Are you sure that you got both projects running ? test_project on
localhost:8000 and test_remote_project on localhost:8001 ?

On Wed, Nov 7, 2012 at 11:43 AM, Dominique Guardiola <
notifications@github.com> wrote:

Switched to a python 2.7 just in case, still got this error
The two URLS you provided are working, but when i'm using the
test_remote_project, and trying to use the autocomplete in the admin, the
URLS are not the same, they're like :

http://localhost:8000/autocomplete/CityRestAutocomplete/?q=res


Reply to this email directly or view it on GitHubhttps://github.com//issues/59#issuecomment-10144114.

http://blog.yourlabs.org
Customer is king - Le client est roi - El cliente es rey.

@domguard
Copy link
Author

domguard commented Nov 7, 2012

mmm... RTFD sorry....

@domguard domguard closed this as completed Nov 7, 2012
@jpic
Copy link
Member

jpic commented Nov 7, 2012

Well I feel a lot better now 🍻

You might also want to check out the video.

Enjoy django-autocomplete-light

@jpic
Copy link
Member

jpic commented Nov 7, 2012

Actually, it shouldn't crash like this if the remote server is down. It should just propose local results instead of trying to decode JSON. Would you like to contribute this ?

@domguard
Copy link
Author

domguard commented Nov 7, 2012

I was just evaluating your package for my project needs
I watched the video, in fact, I wanted external data access, but I did not want to create a new object when an external object is selected, just wanted to fill some internal field of the edited object
Can I easily override this behaviour ?

@jpic
Copy link
Member

jpic commented Nov 7, 2012

Of course, the autocomplete you looked at is AutocompleteRestModel, which of course implies usage of models.

There are many ways to achieve what you want. Choosing the right way depends on your specifications.

For the autocomplete choices, you should override choices_for_request(). You have the choice to inherit from AutocompleteChoiceList, AutocompleteList, AutocompleteBase (bare enough) or AutocompleteInterface (really bare).

For the autocomplete input, you could use autocomplete_light.TextWidget or initialize a javascript Autocomplete instance on your own for complete freedom.

The rest is standard Django: add an extra field (with or without the widget), do your stuff in clean_your_extra_field_name().

Did you read all the docs already ?

If you need extra help, feel free to fork this repo, and create your use case in an app of test_project like test_project/support_domguard/ for example and I'll help you.

Hope this helps.

@jpic
Copy link
Member

jpic commented Nov 7, 2012

You should really read this: http://django-autocomplete-light.readthedocs.org/en/latest/forms.html

I think it will help you understand the whole django-autocomplete-light app, and make your decisions.

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