0

I want to parse GET data which contains #(Example: #HelloThere). I'm getting below error

$ curl http://127.0.0.1:5000/#Hello
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

Code

from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/<code>', methods=['GET'])
def convert(code):
    print code
    return json.dumps({"results": code}), 200

if __name__ == '__main__':
    app.run()

How can I accept GET data which contains #?

I also tried request.args.get('code') and access curl http://127.0.0.1:5000/code=#FFFFFF, still getting same error

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

0

It's getting interpreted as a fragment identifier.

If you must pass a # character as data in the URL, try urlencoding the # character instead as %23

curl http://127.0.0.1:5000/%23Hello

There's more complexity here which you can find in this SO answer: Python - Get URL fragment identifier with Flask

sql_knievel
  • 1,199
  • 1
  • 13
  • 26