Hi Juan,

Take out your try/except block.  It's "lying" in the sense that what's
problematic isn't the failure to download.  The exception handling is
not doing well: it's hiding the true cause of the problem.

After you take the exception handler out, try again.  The error
message should be a lot more localized and tell you exactly what line
number is raising the runtime error.


Ideally, you should read the file-like object progressively, rather
than suck the whole thing at once.  Something like the following:

###############################
import codecs
import urllib.request
urlString = "http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv";
rawFile = urllib.request.urlopen(urlString)
decodedFile = codecs.getreader("utf-8")(rawFile)
for line in decodedFile:
    print(repr(line))
###############################

shows that you can do the decoding on-the-fly.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to