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

Unexpected token B in JSON at position 0 #1

Open
vroger11 opened this issue Aug 3, 2021 · 4 comments
Open

Unexpected token B in JSON at position 0 #1

vroger11 opened this issue Aug 3, 2021 · 4 comments

Comments

@vroger11
Copy link

vroger11 commented Aug 3, 2021

I just wanted to try your API. After installing everything like in the README, I get an Unexpected token error on the example given in the README. Any help will be great, thanks.

All informations (also, I used the version tagged "v1.0"):

Request Method: GET
http://127.0.0.1:8000/v1/vegetation-health/?from=2021-03-01&to=2021-03-30&location=Berlin
3.1.13
SatSearchError
Unexpected token B in JSON at position 0
/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/satsearch/search.py, line 80, in query
/home/vroger/.miniconda3/envs/open_data/bin/python
3.9.6
['/home/vroger/git/api.openspacedata.org', '/home/vroger/.miniconda3/envs/open_data/lib/python39.zip', '/home/vroger/.miniconda3/envs/open_data/lib/python3.9', '/home/vroger/.miniconda3/envs/open_data/lib/python3.9/lib-dynload', '/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages']
Tue, 03 Aug 2021 17:03:48 +0000

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/v1/vegetation-health/?from=2021-03-01&to=2021-03-30&location=Berlin

Django Version: 3.1.13
Python Version: 3.9.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'api']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/home/vroger/git/api.openspacedata.org/api/views.py", line 28, in get
return Response(downloads.data)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/serializers.py", line 548, in data
ret = super().data
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/serializers.py", line 246, in data
self._data = self.to_representation(self.instance)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/serializers.py", line 515, in to_representation
ret[field.field_name] = field.to_representation(attribute)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/rest_framework/fields.py", line 1882, in to_representation
return method(value)
File "/home/vroger/git/api.openspacedata.org/api/serializers.py", line 65, in get_files
items = bbox_search.items()
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/satsearch/search.py", line 90, in items
found = self.found(headers=headers)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/satsearch/search.py", line 62, in found
results = self.query(url=url, headers=headers, **kwargs)
File "/home/vroger/.miniconda3/envs/open_data/lib/python3.9/site-packages/satsearch/search.py", line 80, in query
raise SatSearchError(response.text)

Exception Type: SatSearchError at /v1/vegetation-health/
Exception Value: Unexpected token B in JSON at position 0

@NiklasJordan
Copy link
Member

This is because the ReadMe is not yet customized. Sorry for the confusion. I will adapt the ReadMe shortly. We have now implemented the geocoding in the frontend via Mapbox and pass a BoundingBox to the API. So your request must look like this:

http://127.0.0.1:8000/v1/water/?from=2020-04-10&to=2020-04-20&location=[32.4371337890625,25.809781975840405,32.92877197265625,26.251546424213046]

If you want to re-enable geocoding via the API, all you really need to do is uncomment lines 36 through 40 in the serializer.py, and change line 57 to this:

bbox=bbx,

This should work.

@vroger11
Copy link
Author

Ok thanks for your answer, I will look into it asap

@NiklasJordan
Copy link
Member

@vroger11 Does it work for you?

@vroger11
Copy link
Author

vroger11 commented Sep 6, 2021

Thank you for the reminder. I forgot to check it (I am deeply sorry). It works using your intel! It definitively needs to be specified in the README.

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