1
を見つけた私はこのような権限でGoogleスプレッドシートのドキュメントを読みしようとしています:DictReaderエラー:予想される文字列またはUnicodeオブジェクト、リストは
opener = urllib2.build_opener()
opener.addheaders = [('Accept-Charset', 'utf-8')]
response = opener.open(
"https://docs.google.com/spreadsheets/d/ID/export?format=csv"
)
csv_records = unicodecsv.reader(response, encoding='utf-8')
translations = csv.DictReader(csv_records)
for row in translations:
print row["age"]
しかし、私はエラーを取得する:フィールド名のために、おそらくexpected string or Unicode object, list found
。
どういうところが間違っていますか?
スタックトレース:あなたのケースcsv_records
には、リストを返しますunicodecsv
File "/Users/me/projects/ad_copy.py", line 68, in create_copies
for row in translations
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/csv.py", line 107, in next
self.fieldnames
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/csv.py", line 90, in fieldnames
self._fieldnames = self.reader.next()
TypeError: expected string or Unicode object, list found
印刷する限り、私は理解して
print translations
print csv_records
<csv.DictReader instance at 0x11163fa28>
<unicodecsv.py2.UnicodeReader object at 0x11160da50>
スタックトレースを投稿してください –
翻訳やデータなどのデバッグ情報を印刷しようとしましたか? – rocksteady
スタックトレースを投稿しました – Dejell