Well not really! does not work with '☃.net'<div><br></div><div><div>Traceback (most recent call last):</div><div>  File "<stdin>", line 1, in <module></div><div>  File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen</div>

<div>    return _opener.open(url, data, timeout)</div><div>  File "/usr/lib/python2.6/urllib2.py", line 391, in open</div><div>    response = self._open(req, data)</div><div>  File "/usr/lib/python2.6/urllib2.py", line 409, in _open</div>

<div>    '_open', req)</div><div>  File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain</div><div>    result = func(*args)</div><div>  File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open</div>

<div>    return self.do_open(httplib.HTTPConnection, req)</div><div>  File "/usr/lib/python2.6/urllib2.py", line 1116, in do_open</div><div>    h = http_class(host, timeout=req.timeout) # will parse host:port</div>

<div>  File "/usr/lib/python2.6/httplib.py", line 661, in __init__</div><div>    self._set_hostport(host, port)</div><div>  File "/usr/lib/python2.6/httplib.py", line 686, in _set_hostport</div><div>    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])</div>

<div>httplib.InvalidURL: nonnumeric port: </div><div><div><br></div><br><div class="gmail_quote">On Wed, Jun 13, 2012 at 12:17 PM, Виталий Волков <span dir="ltr"><<a href="mailto:hash.3g@gmail.com" target="_blank">hash.3g@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Answer in this topic should help you to solve issue.</div><div><br></div><a href="http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top" target="_blank">http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top</a> <div>


<br></div><div>Regards.<div><div class="h5"><br><br><div class="gmail_quote">2012/6/13 John Nagle <span dir="ltr"><<a href="mailto:nagle@animats.com" target="_blank">nagle@animats.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


I'm trying to open<br>
<br>
<a href="http://xn--e1afmkfd.xn--80akhbyknj4f" target="_blank">http://пример.испытание</a><br>
<br>
with<br>
<br>
urllib2.urlopen(s1)<br>
<br>
in Python 2.7 on Windows 7. This produces a Unicode exception:<br>
<br>
>>> s1<br>
u'http://\u043f\u0440\u0438\<u></u>u043c\u0435\u0440.\u0438\<u></u>u0441\u043f\u044b\u0442\u0430\<u></u>u043d\u0438\u0435'<br>
>>> fd = urllib2.urlopen(s1)<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
  File "C:\python27\lib\urllib2.py", line 126, in urlopen<br>
    return _opener.open(url, data, timeout)<br>
  File "C:\python27\lib\urllib2.py", line 394, in open<br>
    response = self._open(req, data)<br>
  File "C:\python27\lib\urllib2.py", line 412, in _open<br>
    '_open', req)<br>
  File "C:\python27\lib\urllib2.py", line 372, in _call_chain<br>
    result = func(*args)<br>
  File "C:\python27\lib\urllib2.py", line 1199, in http_open<br>
    return self.do_open(httplib.<u></u>HTTPConnection, req)<br>
  File "C:\python27\lib\urllib2.py", line 1168, in do_open<br>
    h.request(req.get_method(), req.get_selector(), req.data, headers)<br>
  File "C:\python27\lib\httplib.py", line 955, in request<br>
    self._send_request(method, url, body, headers)<br>
  File "C:\python27\lib\httplib.py", line 988, in _send_request<br>
    self.putheader(hdr, value)<br>
  File "C:\python27\lib\httplib.py", line 935, in putheader<br>
    hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))<br>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)<br>
>>><br>
<br>
The HTTP library is trying to put the URL in the header as ASCII.  Why isn't "urllib2" handling that?<br>
<br>
What does "urllib2" want?  Percent escapes?  Punycode?<span><font color="#888888"><br>
<br>
                                John Nagle<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div></div></div>
<br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><i>'I am what I am because of who we all are'</i><br><a href="http://www.h3manth.com" target="_blank">h3manth.com</a><br><i>-- Hemanth HM<span></span><span></span> </i><br>


</div></div>