0

I am currently having this issue. When I add a query to the server (e.g. http://127.0.0.1:5000/?property=Ward&propertyValue=Ely%20North%20Ward, where Ward = Ely North Ward), the JSON returns values. However, if I wanted to filter Wards that contain the "&" character (e.g. Ward = Ely & Christchurch Ward), it does not return any values, just { type: "FeatureCollection", features: [ ] }.

What can I do so that the function reads "&" characters, and returns the correct values from what I entered?

Code below:

from flask import Flask, escape, request 
import requests
import json 



def graphqlwfs(url):
    url = "https://osdatahubapi.os.uk/OSFeaturesAPI/wfs/v1?service=wfs&request=GetCapabilities"
    queryString = "&typenames=osfeatures:BoundaryLine_PollingDistrict&outputformat=geoJSON"


    request_json = request.get_json(silent=True)
    request_args = request.args


    if request_json and 'property' in request_json:
        property = request_json['property']
    elif request_args and 'property' in request_args:
        property = request_args['property']
    else:
        property = ""

    if request_json and 'propertyValue' in request_json:
        propertyValue = request_json['propertyValue']
    elif request_args and 'propertyValue' in request_args:
        propertyValue = request_args['propertyValue']
    else:
        propertyValue = ""


    filterString = "&filter=<Filter><PropertyIsEqualTo><PropertyName>" + str(property) + "</PropertyName><Literal>" + str(propertyValue) + "</Literal></PropertyIsEqualTo></Filter>"

    if property == "":
        filterString = ""
    if propertyValue == "":
        filterString = ""


    newUrl = str(url.replace("GetCapabilities", "GetFeature") + queryString + filterString)
    response = requests.get(newUrl)

    features = response.json()



    return features


        ```







jlsr10
  • 33
  • 5

2 Answers2

0

Try escaping the & character. In this case, the code for & is %26. So you can try

?property=Ward&propertyValue=Ely%20%26%20Christchurch%20Ward

For more information, read this link.

  • returns the following error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) – jlsr10 Nov 20 '19 at 12:43
-1

for me its working fine, may be i'am wrong tell me will change answer, may be needed more description.

a="sad& wasd"
if a=="sad& wasd":
   print("hi") 
output:hi
  • You aren't working with URLs or the `requests` library. The problem isn't with putting a `&` in a string. – chepner Nov 20 '19 at 13:11