python 2 urlopen vs python 3 urlopen

Sean Darcy seandarcy2 at gmail.com
Mon Aug 27 13:25:10 EDT 2018


python 2 :

python
Python 2.7.15 (default, May 15 2018, 15:37:31)
.....
>>> import urllib2
>>> res = urllib2.urlopen('https://api.ipify.org').read()
>>> print res
www.xxx.yyy.zzz

python3

python3
Python 3.6.6 (default, Jul 19 2018, 16:29:00)
...
>>> from urllib.request import urlopen
>>> res = urlopen('https://api.ipify.org').read()
>>> print(res)
b'ww.xxx.yyy.zzz'

I'm expecting the python 2 result, just the ip address. How can I get
python 3 just to give the address, and not include  b'      '  ? I
know I can mess with string manipulation, but I want to keep it
simple.

sean



More information about the Python-list mailing list