O
O
ororambo2016-11-22 13:45:25
Flask
ororambo, 2016-11-22 13:45:25

Flask and problems with '&' character in URL?

There is a url:
site.com/?foo=bar& Request.url

turns out to be site.com/?foo=bar Turns
out to be foo=bar in

request.query_string '&' from 'bar&' is lost. Question: how to get a GET parameter with & at the end

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pcdesign, 2016-11-22
@ororambo

In general, this is of course not correct, but it can be done like this:

@app.route('/foo')
def foo():
    raw = str(request)
    return raw

I got this answer:
Then parse this line with a regular regular expression and get a parameter.
@app.route('/foo')
def foo():
    raw = str(request)
    print(raw)
    p = re.compile(r"""(\?|\&)([^=]+)\=(?P<val>([^']+))""")
    r = p.search(raw)
    return r.group("val")

A
Alexander, 2016-11-22
@NeiroNx

"http://site.com/?"+urllib.quote_plus("foo=bar&")
urllib.unquote_plus("string%26%25%3A")

read urllib documentation

V
Vladimir, 2016-11-22
@vintello

and why actually problems?
in the specified variant everything worked correctly. because the symbol

&
is intended to point to the next parameter. which you don't have. hence it simply ignored it as unnecessary in this context.
you just need to understand why you need this symbol

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question