Reputation: 21711
I write a python script to retrieve the image from url:
url = `https://uploads0.wikiart.org/images/albrecht-durer/watermill-at-the-montaсa.jpg`
urllib.request.urlretrieve(url, STYLE_IMAGE_UPLOAD + "wikiart" + "/" + url)
When I run I got the message
UnicodeEncodeError: 'ascii' codec can't encode character '\u0441' in position 49: ordinal not in range(128)
I think the problem from the image url
'https://uploads0.wikiart.org/images/albrecht-durer/watermill-at-the-monta\u0441a.jpg',
How to fix this problem?
Upvotes: 0
Views: 405
Reputation: 5817
The URL contains a non-ASCII character (a Cyrillic letter that looks like a Latin "c").
Escape this character using the urllib.parse.quote
function:
url = 'https://uploads0.wikiart.org' + urllib.parse.quote('/images/albrecht-durer/watermill-at-the-montaсa.jpg')
urllib.request.urlretrieve(url, '/tmp/watermill.jpg')
Don't put the entire URL in the quote
function, otherwise it would escape the colon (":") in "https://".
Upvotes: 1