Can you format a Python Traceback?

Asked

Viewed 120 times

2

Is there any way to format Python Traceback to get a better reading of the error request? For example, I received the following request on my traceback:

"<WSGIRequest\npath:/admin/verificacao/verificacao/1849/,\nGET:<QueryDict: {}>,\nPOST:<QueryDict: {u'trajeto': [u''], u'concluido': [u'1'], u'_save': [u'Salvar'], u'consultor': [u'18'], u'resposta_21': [u'As parcerias realizadas.\\r\\nDedica\\xe7\\xe3o da equipe envolvida.\\r\\nPlanejamento para os eventos.\\r\\nImplementa\\xe7\\xe3o essencial da pol\\xedtica pedag\\xf3gica.\\r\\nEstudo pr\\xe9vio dos pontos de fragilidade das comunidades.'], u'resposta_20': [u'A extens\\xe3o territorial \\xe9 do estado de goi\\xe1s, podendo estender-se \\xe0s outras defensorias.\\r\\n'], u'resposta_23': [u'78 processos ativos que foram arquivados na comunidade do Assentamento de Canudos.\\r\\n'], u'resposta_22': [u'Praticamente todas foram superadas com a parte pedag\\xf3gica e negocial.\\r\\nHavia as dificuldades para levar ao conhecimento do jurisdicionado seus direitos e at\\xe9 mesmo os benef\\xedcios que possu\\xedam.\\r\\n'], u'resposta_25': [u'1. Superintend\\xeancia Regional do Incra em Goi\\xe1s.\\r\\n2. Prefeitura Municipal de Campestre de Goi\\xe1s, Goi\\xe1s.\\r\\n3. Banco do Brasil\\r\\n4. Colaboradores volunt\\xe1rios da \\xe1rea de produ\\xe7\\xe3o rural, assistentes sociais.\\r\\n'], u'resposta_24': [u'Aproximadamente 337 fam\\xedlias e 1118 pessoas considerando a quantidade de integrantes das fam\\xedlias abarcadas pelo projeto.\\r\\n'], u'resposta_19': [u'1 ano e 2 meses'], u'resposta_17': [u'O problema \\xe0 ser resolvido era a insatisfa\\xe7\\xe3o na entrega jurisdicional pela sua pr\\xf3pria inefic\\xe1cia, quando existia um assentamento. \\r\\nIgnor\\xe2ncia dos pr\\xf3prios assentados quanto aos benef\\xedcios.\\r\\nIgnor\\xe2ncia quanto ao movimento, pois existiam v\\xe1rios movimentos e achavam que a defensoria seria mais um.\\r\\nExistia um insucesso muito grande nas demandas judiciais.\\r\\nPor mais que existiam benef\\xedcios, n\\xe3o eram do conhecimento dos assentados.\\r\\nFalta de estrutura f\\xedsica e operacional para levar o conhecimento dos benef\\xedcios dos assentados.\\r\\n'], u'proposta': [u'4512'], u'csrfmiddlewaretoken': [u'FQlzjFRtKmaT9HWjfIyXk4IK3PNwHA96'], u'resposta_18': [u'1\\xba Identifica\\xe7\\xe3o do problema e realiza\\xe7\\xe3o do planejamento\\r\\n2\\xba Definir um evento como solu\\xe7\\xe3o adequada.\\r\\n3\\xba formula\\xe7\\xe3o do plano pedag\\xf3gico\\r\\n4\\xba Forma\\xe7\\xe3o das parcerias.\\r\\n5\\xba Plano operacional - Visitas aos locais, com parcerias com as prefeituras para\\r\\nrealiza\\xe7\\xe3o dos eventos.'], u'slug': [u'dpu-no-campo-4512-altivojr']}>,\nCOOKIES:{'__utma': '63901038.1404066889.1409656010.1409656010.1409666214.2',\n '__utmz': '63901038.1409666214.2.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)',\n 'csrftoken': 'FQlzjFRtKmaT9HWjfIyXk4IK3PNwHA96',\n 'mp_4cb22527c5133fdb99a210c6664dcb0f_mixpanel': '%7B%22distinct_id%22%3A%20%22148360bb47a5de-0063bfb2f-4e40012c-100200-148360bb47b5a7%22%2C%22%24search_engine%22%3A%20%22google%22%2C%22%24initial_referrer%22%3A%20%22https%3A%2F%2Fwww.google.com%2F%22%2C%22%24initial_referring_domain%22%3A%20%22www.google.com%22%7D',\n 'sessionid': 'ec5ef2aa54e3451a108ffed9929bba8d'},\nMETA:{'CONTENT_LENGTH': '3482',\n 'CONTENT_TYPE': 'multipart/form-data; boundary=----WebKitFormBoundaryedY6h7JfsgGlDEvU',\n 'CSRF_COOKIE': 'FQlzjFRtKmaT9HWjfIyXk4IK3PNwHA96',\n 'DOCUMENT_ROOT': '/var/www/html',\n 'GATEWAY_INTERFACE': 'CGI/1.1',\n 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',\n 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',\n 'HTTP_ACCEPT_LANGUAGE': 'pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4',\n 'HTTP_CACHE_CONTROL': 'max-age=0',\n 'HTTP_CONNECTION': 'keep-alive',\n 'HTTP_COOKIE': 'mp_4cb22527c5133fdb99a210c6664dcb0f_mixpanel=%7B%22distinct_id%22%3A%20%22148360bb47a5de-0063bfb2f-4e40012c-100200-148360bb47b5a7%22%2C%22%24search_engine%22%3A%20%22google%22%2C%22%24initial_referrer%22%3A%20%22https%3A%2F%2Fwww.google.com%2F%22%2C%22%24initial_referring_domain%22%3A%20%22www.google.com%22%7D; __utma=63901038.1404066889.1409656010.1409656010.1409666214.2; __utmz=63901038.1409666214.2.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); sessionid=ec5ef2aa54e3451a108ffed9929bba8d; csrftoken=FQlzjFRtKmaT9HWjfIyXk4IK3PNwHA96',\n 'HTTP_HOST': 'www.premioinnovare.com.br',\n 'HTTP_ORIGIN': 'http://www.premioinnovare.com.br',\n 'HTTP_REFERER': 'http://www.premioinnovare.com.br/admin/verificacao/verificacao/1849/',\n 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36',\n 'HTTP_X_FORWARDED_FOR': '186.214.161.180',\n 'HTTP_X_FORWARDED_PORT': '80',\n 'HTTP_X_FORWARDED_PROTO': 'http',\n 'PATH_INFO': u'/admin/verificacao/verificacao/1849/',\n 'PATH_TRANSLATED': '/opt/innovare/website/website/wsgi.py/admin/verificacao/verificacao/1849/',\n 'QUERY_STRING': '',\n 'REMOTE_ADDR': '10.140.200.104',\n 'REMOTE_PORT': '21830',\n 'REQUEST_METHOD': 'POST',\n 'REQUEST_URI': '/admin/verificacao/verificacao/1849/',\n 'SCRIPT_FILENAME': '/opt/innovare/website/website/wsgi.py',\n 'SCRIPT_NAME': u'',\n 'SERVER_ADDR': '10.111.156.250',\n 'SERVER_ADMIN': 'root@localhost',\n 'SERVER_NAME': 'www.premioinnovare.com.br',\n 'SERVER_PORT': '80',\n 'SERVER_PROTOCOL': 'HTTP/1.1',\n 'SERVER_SIGNATURE': '<address>Apache/2.2.27 (Amazon) Server at www.premioinnovare.com.br Port 80</address>\\n',\n 'SERVER_SOFTWARE': 'Apache/2.2.27 (Amazon)',\n 'mod_wsgi.application_group': 'ip-10-111-156-250.ec2.internal|',\n 'mod_wsgi.callable_object': 'application',\n 'mod_wsgi.handler_script': '',\n 'mod_wsgi.input_chunked': '0',\n 'mod_wsgi.listener_host': '',\n 'mod_wsgi.listener_port': '80',\n 'mod_wsgi.process_group': 'innovare',\n 'mod_wsgi.request_handler': 'wsgi-script',\n 'mod_wsgi.script_reloading': '1',\n 'mod_wsgi.version': (3, 2),\n 'wsgi.errors': <mod_wsgi.Log object at 0x7f66943a7870>,\n 'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f668c3e6648>,\n 'wsgi.input': <mod_wsgi.Input object at 0x7f66943a74b0>,\n 'wsgi.multiprocess': True,\n 'wsgi.multithread': True,\n 'wsgi.run_once': False,\n 'wsgi.url_scheme': 'http',\n 'wsgi.version': (1, 1)}>"

Only it’s really bad to read it like that. Has some way to make it more pleasing to the eye and more understandable?

  • On what platform did you run this? My tracebacks on linux are much less unpleasant!

  • The application runs on a Ubuntu machine that sends me tracebacks by email with send_mail()

  • Only the request of traceback that is horrible like this, the rest of the traceback is quieter.

  • I get it. I think it might be because of send_mail() then. There is no way to send the request 'pure' try to send it by changing the \n by lines even? detail

  • I spoke to the staff here and send_mail() is native to the Amazon SNS service. It just picks up the traceback and sends so I would really need a formatter. Something like Json Formatter (http://jsonformatter.curiousconcept.com/)

  • I get it. Better than reading this ai XD

Show 1 more comment

1 answer

1


This does not seem to me a traceback. Apparently someone passed an object WSGIRequest as if it were a Exception or an error message (string) already formatted. Then Python simply converted to string in the easiest way, using __repr__.

I imagine the mistake lies where you’re trying to pass the Exception for your logger.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.