0
import Flask
app.route('/urlinfo/1/<URL>', methods=['GET'])
def search(URL):
  print URL

I am making curl command to to test it

curl  http://127.0.0.1:5000/urlinfo/1/http://www.dsdsd.com

Since URL include '//' Flask consider it as a second argument and throw an error.

1.How to pass whole URL as an one argument in

curl http://127.0.0.1:5000/urlinfo/1/http://www.dsdsd.com/path command?

2.How to check that Enter URL is valid?

guri
  • 1,521
  • 2
  • 14
  • 20

1 Answers1

3

Change your decorator to this:

@app.route('/urlinfo/1/<path:URL>', methods=['GET'])

By adding path to the URL arguments, slashes should be accepted.

Jake Conway
  • 901
  • 16
  • 25
  • Thanks yeah It resolved the issue.how can i verify that URL is valid.I mean basic check? – guri Nov 17 '16 at 06:31
  • @guri take a look at this answer http://stackoverflow.com/a/32171869/7090605 – Jake Conway Nov 17 '16 at 06:35
  • Thanks for sharing the link.I stumble upon it earlier but I am trying to avoid installing extra package and trying to achieve with inbuilt libraries – guri Nov 17 '16 at 06:44
  • @guri you could always borrow the code for the method from that package. It uses `re`, which is a builtin library. https://github.com/kvesteri/validators/blob/master/validators/domain.py – Jake Conway Nov 17 '16 at 06:46
  • I am using the way you said **@app.route('/urlinfo/1/', methods=['GET'])** and it is now treating URL as a single argument but when I am passing URL like **http://127.0.0.1:5000/urlinfo/1/'https://www.youtube.com/watch?v=6RB89BOxaYY'** it is neglecting URL after '?'.Is there any way it does not neglect URL after '?' – guri Nov 17 '16 at 08:59
  • @guri concatenate `str(request.query_string)` to the URL string before printing it. Right now, Flask things that `?v=6RB89BOxaYY%27` is a URL query, and not part of the URL, so you have to add it back with `request.query_string`. – Jake Conway Nov 17 '16 at 13:09
  • [Percent encoding](https://en.m.wikipedia.org/wiki/Percent-encoding) the `?` (`%3F`) may do the trick. – dirn Nov 17 '16 at 13:09