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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...