0
api = Flask(__name__)

@api.route('/entities', methods=['GET'])
def entities():
    text = request.args.get('text')
    entities = str(nlu.entities(text))
    return entities

http://0.0.0.0:5000/entities?text=#test

The symbol # cause the problem, in which 'text' is empty inside:

text = request.args.get('text')

I want to use urlencode to deal with special characters. But where to use it? This is for a http service call. Should I expect the client to encode the URL before it calls the URL?

http://0.0.0.0:5000/entities?text=#test

Is there a way in my Flask backend to handle these special characters, in case clients haven't encode it properly?

marlon
  • 6,029
  • 8
  • 42
  • 76
  • hope these post's might help you :) 1) https://stackoverflow.com/questions/49847076/how-to-route-non-ascii-urls-in-flask-python .. 2) https://stackoverflow.com/questions/18752995/how-to-get-access-to-the-url-segments-after-a-in-python-flask – KcH Jun 11 '20 at 06:47
  • 1
    If the client doesn't encode the character, Flask is never even *seeing* it since the browser won't even send it to the server. The client is required to encode the character correctly. – deceze Jun 11 '20 at 06:48
  • @deceze. That's good info and good to know. – marlon Jun 11 '20 at 06:51
  • Related: https://www.brainyquote.com/quotes/charles_babbage_141832 ;) – deceze Jun 11 '20 at 07:16

0 Answers0