Skip to content Skip to sidebar Skip to footer

Python Not Concatenating String And Unicode To Link

When I append a Unicode string to the end of str, I can not click on the URL. Bad: base_url = 'https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content

Solution 1:

It appears that you're printing the results in an IDE, perhaps PyCharm. You need to percent encode a UTF-8 encoded version of the string:

import urllib

base_url = 'https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles='
name = u"Ángel_Garasa"print base_url + urllib.quote(name.encode("utf-8"))

This shows: image showing clickable link with percent encoded portion

In your case you need to update your code, so that the relevant field from the database is percent encoded. You only need to encode this one field to UTF-8 just for the percent encoding.

Post a Comment for "Python Not Concatenating String And Unicode To Link"