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

Querying a name with "space" in between returns TypeError on Overpass Query #6

Closed
mtmendoza opened this issue Nov 24, 2017 · 3 comments

Comments

@mtmendoza
Copy link

Hi! I'd like to ask how to resolve the issue where querying an overpass name that most probably be because of a space in between causes a TypeError.

This is how the code looks like in my python views:

def query_overpass(request):
    query = request.GET['query']
    print(query)
    overpass = Overpass()
    city_query = "rel[name="+ query + "][type=boundary][boundary=administrative];out geom;"
    city_boundary = overpass.query(city_query)
    result = json.dumps(city_boundary.toJSON())
    return render(request, 'plexus/home.html', {'result': result})

and the error it raises:

Quezon City
Internal Server Error: /search/
Traceback (most recent call last):
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/gridlockdev/Desktop/heroku/grace/network/views.py", line 40, in query_overpass
    city_boundary = overpass.query(city_query)
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/OSMPythonTools/internal/cacheObject.py", line 38, in query
    result = self._rawToResult(data, queryString)
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/OSMPythonTools/overpass.py", line 44, in _rawToResult
    return OverpassResult(data, queryString)
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/OSMPythonTools/overpass.py", line 73, in __init__
    self._elements = list(map(lambda e: Element(json=e), self.__get('elements')))
  File "/home/gridlockdev/Desktop/heroku/grace/env/lib/python3.5/site-packages/OSMPythonTools/overpass.py", line 87, in __get
    return self._json[prop] if prop in self._json else None
TypeError: argument of type 'NoneType' is not iterable

At first I assumed that there really might be no element to return, but I tried it over at Overpass Turbo and it returns exactly what I want. See: http://overpass-turbo.eu/s/tfP

Other than this problem, it works great! 👍

Hope you could help! Thanks in advance!

@mocnik-science
Copy link
Owner

mocnik-science commented Nov 24, 2017

Hi Theresa,
in Overpass Turbo, you used quotation marks. If you add them to your code, it should work:

def query_overpass(request):
    ...
    city_query = "rel[name=\""+ query + "\"][type=boundary][boundary=administrative];out geom;"
    ...

Does this solve your problem?

@mtmendoza
Copy link
Author

YES! Thank you for a quick response! I did not notice that small mistake since it queries nicely on single names. :)

@mocnik-science
Copy link
Owner

Great to hear. If you like osm-python-tools, feel free to "star" it. ;)

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