Using Python 2.5.2 and Linux Debian, I'm trying to get the content from a Spanish URL that contains a Spanish char 'í'
:
import urllib
url = u'http://mydomain.es/índice.html'
content = urllib.urlopen(url).read()
I'm getting this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'xe1' in position 8: ordinal not in range(128)
I've tried using before passing the url to urllib this:
url = urllib.quote(url)
and this:
url = url.encode('UTF-8')
but they didn't work.
Can you tell me what I am doing wrong ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…