Quote:_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
urlopen()
always return bytes and csv reader need string.Then it's to late to decode on row.
import urllib.request import csv url = 'adress' site = urllib.request.urlopen(url) with open(site.read().decode('utf-8')) as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row)Use always Requests then do not need to guess on encoding as get correct encoding from site.
import requests url = 'adress' site = requests.get(url) with open(site.text) as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row)It's usually utf-8,but csv files can have other encoding.
>>> import requests >>> >>> url = 'https://www.stats.govt.nz/....bands-csv.csv' >>> site = requests.get(url) >>> site.encoding 'ISO-8859-1'Also one of the simplest way out there is to use Pandas.
import pandas as pd data = pd.read_csv('https://some.csv')