X
X
xSkyFoXx2012-04-02 10:52:25
Python
xSkyFoXx, 2012-04-02 10:52:25

urllib.urlopen and Russian URLs

Tell me, how can urllib'oy open Russian URLs?
All sorts of options:

urllib2.urlopen(u'http://my_site/method?¶m1=Русский текст'.encode('utf-8'))

either or do not help.
text = u'Русский текст c пробелом'
urllib2.urlopen(u'http://my_site/method?¶m1=%s' % text)


text = unicode(u'Русский текст c пробелом')
urllib2.urlopen(u'http://my_site/method?¶m1=%s' % text)


Answer the question

In order to leave comments, you need to log in

4 answer(s)
U
un1t, 2012-04-02
@un1t

this was for parameters, and for domains you need to use punycode
'domain.rf'.encode('idna')

U
un1t, 2012-04-02
@un1t

urllib.urlencode({'param': u'text'.encode('utf-8')})

V
Vas3K, 2012-04-02
@Vas3K

If I understood you correctly, then you are trying to open IRI as a URI, which is not entirely correct. There are many methods for translating from IRI. You can just use urllib.unquote(), but it doesn't always work. Therefore, we google for the request “python iri to uri” and copy the necessary code. There is a small method, I personally ripped from the Django framework (like django.utils.encoding.iri_to_uri)

S
SERGE_GAM, 2018-05-09
@SERGE_GAM

Example for ' https://bdt.spb.ru/poster ':
bdt = ' https://bdt.spb.ru/ '+ quote('poster')
urllib.request.urlopen(bdt)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question