I am passing a query id object to a view, which then fetches the object and then calls the following func:
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]
)
But without returning from the function, I get this error when I request the page:
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'>)
But when I call the same function in a django shell, this works fine. I am stumped.
What I want to know is why:
1. it works in the shell and not on the web-server.
2. how do I make it work on the web-server with Django/WSGI.
Thanks.
Because the system default local for Apache is often ASCII, whereas in your user account it is UTF-8.
You either fix the code so as not to rely on implicit coercion, which will use the system default encoding for the process, or you override Apache init environment so as to set LANG to a UTF-8 variant.
Try googling for ‘Apache UTF-8 locale’ and find the appropriate way of doing it for your Apache distro.