Python 2 -> 3, urllib.urlopen (corrected the case)
Irv Kalb
Irv at furrypants.com
Sat Oct 14 20:12:22 EDT 2017
Thank you!
> On Oct 14, 2017, at 12:10 PM, Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
>
> Irv Kalb <Irv at furrypants.com> writes:
>
> Lots of detail snipped. I hope it won't matter...
>
>> <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
>>
>> Huh???
>>
>> I've read a bunch of documentation, and it looks like I'm doing
>> everything right, but I cannot get this to work. Any other
>> suggestions to get this 3 line program to work correctly?
>
> 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
> Maybe you are missing some crucial certificates? Presumably Python
> finds them is standard paces, so it would be worth trying other accesses
> of the URL.
I am just using an absolutely standard install from Python.org
> 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.
>
> --
> Ben.
>
That DID fix it. I changed the URL to add 'download/' and it worked perfectly.
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.
Thanks very much for tracking this down!
Irv
More information about the Python-list
mailing list