osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

python 2 urlopen vs python 3 urlopen


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