Python 2 -> 3, urllib.urlopen (corrected the case)

Irv Kalb Irv at furrypants.com
Sun Oct 15 14:56:27 EDT 2017


> On Oct 14, 2017, at 6:46 PM, Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
> 
> Irv Kalb <Irv at furrypants.com> writes:
> 
>> Thank you!
> 
> You're welcome.
> 
> <snip>
>>> Just a data point...  It works here:
>>> 
>>> $ python3 t.py
>>> Response is:  b'156.99\n'
>>> $ cat t.py
>>> import urllib.request
>>> fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'
>>> # read all the data
>>> response = urllib.request.urlopen(fullURLWithParameters).read()
>>> 
>>> print('Response is: ', response)
>>> $ python3 --version
>>> Python 3.5.2
>> 
>> I have not tried this on anything but my Mac.  I'm running 3.6.1
> <snip>
>>> For example, here:
>>> 
>>> $ wget -q -O - 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' 
>>> 156.99
>>> 
>>> Finally, wget -S shows that the resource has moved.  It is now at
>>> 
>>> Location: http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1
>>> 
>>> I don't think this has anything to do with your problem, but it's worth
>>> noting.
>> 
>> That DID fix it.  I changed the URL to add 'download/' and it worked
>> perfectly.
> 
> That's... interesting.
> 
>> Apparently, Python 3 differs from Python 2 in the way that it is
>> handling a missing/forwarding URL, because the original code in Python
>> 2.7 works perfectly.
> 
> Python 3 works for me.  I still suspect it's some system difference
> rather than being, say, a 3.6.1 vs 3.5.2 difference.  What happens if
> you change the URL to use https rather than http?
> 
> -- 
> Ben.
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

Trying https (with and without the "download." part) results in the same traceback as I was seeing earlier.

Thanks again,

Irv


More information about the Python-list mailing list