でバイトは0x80をデコードすることができない私は、オブジェクトをフェッチし、次のFUNCを呼び出しビューにクエリIDオブジェクトを渡しています:DjangoUnicodeDecodeError:「UTF8」コーデックは位置51
def portAdmin(self,status):
status = status
self.adminStateDict = {
'activate': tuple([tuple([1,3,6,1,2,1,2,2,1,7,self.snmpPortOID]),rfc1902.Integer32(1)]),
'deactivate' : tuple([tuple([1,3,6,1,2,1,2,2,1,7,self.snmpPortOID]),rfc1902.Integer32(2)]),
}
(errorIn, activateErrorStatus, errorIndex, varBinds) = cmdgen.CommandGenerator().setCmd(
cmdgen.CommunityData('my-agent', '.xxxx', 0),
cmdgen.UdpTransportTarget((self.snmpIp, 161)),
self.adminStateDict[status]
)
しかしなし
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 203, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 59, in technical_500_response
html = reporter.get_traceback_html()
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 117, in get_traceback_html
frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']]
File "/usr/local/lib/python2.7/dist-packages/django/template/defaultfilters.py", line 34, in _dec
args[0] = force_unicode(args[0])
File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py", line 93, in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 51: invalid start byte. You passed in 'MibTableColumn((1, 3, 6, 1, 6, 3, 18, 1, 1, 1, 4), \x80\x00O\xb8\x05\xc0\xa8\x06 \x0c\r)' (<type 'str'>)
しかし、私はDjangoのシェルで同じ関数を呼び出すとき、これは正常に動作します:関数から戻って、私はページを要求したとき、私はこのエラーを取得します。私は困惑している。 私が知りたいのは、なぜですか: 1.これはシェルで動作し、Webサーバーでは動作しません。 2. Django/WSGIを使ってWebサーバー上で動作させるにはどうすればいいですか?
ありがとうございました。
Thanks Graham。私がコードを操作している間に、コードのロジックをModelのインスタンスメソッドに再組み込みすることで回避策を見つけました。何らかの理由で、オブジェクトを取得してからSNMP変数を渡す(pySnmpを使用)の間に何かが間違っています。 このようなエラーが発生した場合は、ロジックをviews.pyからmodels.pyに移行することで、すぐに修正できます。前述のように 'Apache UTF-8 locale'を調べます。 – imen