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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...

Updated Data Management and AWS GDI Inventory in Splunk Observability

We’re making some changes to Data Management and Infrastructure Inventory for AWS. The Data Management page, ...