Python not concatenating string and unicode to link

2024/10/15 17:13:58

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&format=xml&titles='url = base_url + u"Ángel_Garasa"
print url

The final output for a name with accents

Good:

base_url = 'https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles='url = base_url + u"Toby_Maquire"
print url

The final output for a name without accents

Answer

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 urllibbase_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.

https://en.xdnf.cn/q/117811.html

Related Q&A

Decrypt python/django password with Symfony 2.5 (using symfony security)

I want to use symfony 2.5.10 security in order to login in from users that were created with pyhton/django security. Passwords in db that are encrypted in this format:pbkdf2_sha256$12000$dVPTWPll8poG$3…

Reuse getCmd object in pysnmp

In the pysnmp documentation there is a getCmd class, I was wondering if it was possible to just instantiate the class once and reuse it at a later point by passing it new oids. I am not sure if the ge…

Django plugged into Apache not working like Django standalone

I have encountered a hodgepodge of errors trying to bring my django site into production with Apache. Having finally gotten mod_wsgi sorted and Apache at least seeming to be trying to load the site Im …

How to filter overlap rows in a big file in python

I am trying to filter overlap rows in a big file in python.The overlap degrees is set to 25%. In other words,the number of element of intersection between any two rows is less than 0.25 times of union …

Installing wxPython in Ubuntu 12.10

I am trying to install wxPython on my Ubuntu 12.10 but with no success. I have gone through all the answers given on this website. Can someone please help me in this or point me in the right direction.…

Open a file name +date as csv in Python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

TextCtrl providing an out of bound exception in wxPython

I am new to WX, so I decided to make a program that will periodically write out a line of text to the screen based on an outside input. The basis of the program contains a basic window with the multili…

Matplotlib: different color for every point of line plot

Im trying to make a plot like in the following figure (source of image): Im talking about the plot in the right panel even though there is some correlation between the two panels: the colorbar. Just s…

getting template syntax error in django template

my code in view :tracks = client.get(/tracks, order=hotness, limit=4) artwork_url=[] for track in tracks:artwork_url.append(str(track.artwork_url).replace("large", "t300x300")) …

Python threading:Is it okay to read/write multiple mutually exclusive parts of a file concurrently?

I know we can guarantee correctness either by locking or using a specialized thread whose sole job is to read/write and communicate with it through queue. But this approach seems logically ok, so I wan…