UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7601: ordinal not in range(128)
Question: I am currently running: Python 3.5.1 :: Anaconda 4.0.0 (x86_64).

ERROR: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
7601: ordinal not in range(128)

When running the below code I get the above error. When I save and try to open
the txt file from a local directy I experience the same error, however, when I
save and run a duplicate, that I shorten to ~25 lines the run as expected --
any guidance would be very much appreciated.

    
    
    import numpy as np
    import matplotlib.pyplot as pp
    import seaborn
    import urllib.request
    
    
    urllib.request.urlretrieve('ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt','stations.txt')
    
    print(open('stations.txt','r').readlines()[:10])
    


Answer: Unfortunately, the [documentation for that
directory](http://www1.ncdc.noaa.gov/pub/data/ghcn/daily/readme.txt) does not
specify what codec is used for the files, so I opened the file in binary mode
instead and found the bytes that caused 'offense'.

The data is encoded as UTF-8; the 'offending' bytes you encounter spell out
ESPAñOLA:

    
    
    >>> line
    b'US1NMRA0022  36.0456 -106.1517 1955.0 NM ESPA\xc3\xb1OLA 5.4 WNW                           \n'
    >>> line.decode('utf8')
    'US1NMRA0022  36.0456 -106.1517 1955.0 NM ESPAñOLA 5.4 WNW                           \n'
    

That's the 63815th line in the file, if you are curious, which is why you
don't see this issue when you truncate the file.

Open the file with that codec:

    
    
    open('stations.txt', 'r', encoding='utf8')
    

Don't rely on the default, which depends on your locale (which easily differs
from environment to environment).

