1π
β
In a case like this, I would personally use a query string for your parameters. The example given above would use:
/example/?param1=http%3A%2F%2Fcnn.com¶m2=red¶m3=22
In Python 3, you would do this with:
import urllib.parse
urllib.parse.urlencode({'param1': 'http://cnn.com', 'param2': 'red', 'param3': '22'})
In Python 2, you would do this with:
import urllib
urllib.urlencode({'param1': 'http://cnn.com', 'param2': 'red', 'param3': '22'})
If, on the other hand, you absolutely have to keep them as part of the actual path, you could simply apply url quoting prior to constructing the URL, so your URL would then look like:
/example/http%3A%2F%2Fcnn.com/red/22/
In Python 3, you would do this with:
import urllib.parse
urllib.parse.quote_plus('http://cnn.com')
In Python 2, you would use:
import urllib
urllib.quote_plus('http://cnn.com')
π€Joey Wilhelm
Source:stackexchange.com