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 May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...