Getting Data In

Splunk組み込みPython以外でUnicodeEncodeErrorが発生する

ts_splunk
Path Finder

splunk cmd python xxxxxx.py
と実行すると正しく実行されるPythonスクリプトがあります。

同じスクリプトを別途インストールしたPython環境ではUnicodeEncodeErrorが発生します。
PythonのバージョンはSplunk組み込みのものと同じです。

問題の箇所は下記の部分です。

with codecs.open('xxxxxxxxx.py', 'rb', 'utf-8-sig') as f:
reader = csv.DictReader(f, dialect=csv.excel)
for row in reader:
.....

同じバージョンのPythonでなぜエラーの差が出るか分かりますでしょうか?

Tags (3)
0 Karma
1 Solution

ts_splunk
Path Finder

Splunk組み込みのPythonでは、sys.setdefaultencoding('utf-8')でデフォルトエンコードを変更してあるんですね。

sys.setdefaultencoding('utf-8')
を設定すれば解決しました。

View solution in original post

0 Karma

ts_splunk
Path Finder

Splunk組み込みのPythonでは、sys.setdefaultencoding('utf-8')でデフォルトエンコードを変更してあるんですね。

sys.setdefaultencoding('utf-8')
を設定すれば解決しました。

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to January Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...

[Puzzles] Solve, Learn, Repeat: Reprocessing XML into Fixed-Length Events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...