When I want to consult a url with Python, it gives me the error:
UnicodeEncodeError: 'ascii' codec can't encode character '\xf3' in position 51: ordinal not in range(128)
What should I add to my code to be able to query smoothly?
from PIL import Image
url='https://tpcgroup-int.com/wp-content/uploads/2020/09/TPC-Chile_-obligación-de-declaraciónes-de-p
recios-de-transferencia-.png'
image = Image.open(urllib.request.urlopen(url))
Thanks in advance.
As in any request, the URL must be URL-encoded so that it can be resolved correctly. Not only in python; whenever you make a request for a URL.
In the urllib library, quote (and unquote for the reverse process) is available.