After much research and help from a DBA in a company the solution to the 
problem was to put the following in the mysqld section of the my.ini file:

max_allowed_packet=128M

I think that the HTML header was so large that when the middleware made a 
call to MySQL it couldn't handle the size of the packet, which I am told is 
only 1MB by default for windows.

On Tuesday, September 10, 2013 11:01:42 AM UTC-3, Paul Childs wrote:
>
> Environment: Django 1.4, MySQL 5.5.33
>
> In one of my views I am consistently getting  a MySQL 
> error: OperationalError: (2006, 'MySQL server has gone away')
>
> Traceback (most recent call last):
>   File "C:\Python26\Lib\wsgiref\handlers.py", line 93, in run
>     self.result = application(self.environ, self.start_response)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\contrib\staticfiles\handlers.py",
>  
> line 67, in __call__
>     return self.application(environ, start_response)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\wsgi.py", 
> line 241, in __call__
>     response = self.get_response(request)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py", 
> line 191, in get_response
>     signals.got_request_exception.send(sender=self.__class__, 
> request=request)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\dispatch\dispatcher.py", 
> line 172, in send
>     response = receiver(signal=self, sender=sender, **named)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\db\__init__.py", line 
> 62, in _rollback_on_exception
>     transaction.rollback_unless_managed(using=conn)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\db\transaction.py", 
> line 129, in rollback_unless_managed
>     connection.rollback_unless_managed()
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\db\backends\__init__.py", 
> line 214, in rollback_unless_managed
>     self._rollback()
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\db\backends\mysql\base.py",
>  
> line 404, in _rollback
>     BaseDatabaseWrapper._rollback(self)
>   File 
> "C:\virtual_env\sitar_env2\lib\site-packages\django\db\backends\__init__.py", 
> line 54, in _rollback
>     return self.connection.rollback()
> OperationalError: (2006, 'MySQL server has gone away')
> [10/Sep/2013 10:29:11] "GET /trending/res_entry/pim/0/ HTTP/1.1" 500 59
>
> Looking at the stack trace it didn't look like the problem was with my 
> view.
>
> I traced through the code and the error occurs in one of the middleware 
> methods that is executed when I redirect to another page:
>
> > c:\virtual_env\sitar_env2\cissimp\trending\views.py(67)res_management()
> -> q_ress = Res.objects.filter(maintenance_phase=maintenance_phase)   #### 
> Hitting the DB OK here
> (Pdb)
> > c:\virtual_env\sitar_env2\cissimp\trending\views.py(69)res_management()
> -> res_list = fmas.get_ress(q_ress, mode, maintenance_phase)
> (Pdb)
> > c:\virtual_env\sitar_env2\cissimp\trending\views.py(70)res_management()
> -> request.session['my_res_list'] = res_list
> (Pdb)
> > c:\virtual_env\sitar_env2\cissimp\trending\views.py(71)res_management()
> -> return redirect('/trending/res_{0}/{1}/1/'.format(mode,
> (Pdb)
> > c:\virtual_env\sitar_env2\cissimp\trending\views.py(72)res_management()
> -> maintenance_phase))
> (Pdb)
> --Return--
> > 
> c:\virtual_env\sitar_env2\cissimp\trending\views.py(72)res_management()-><django....04E53470>
> -> maintenance_phase))
> (Pdb)
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(124)get_response()
> -> if response is None:
> (Pdb) response is None
> False
> (Pdb) n
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(133)get_response()
> -> if hasattr(response, 'render') and callable(response.render):
> (Pdb) l
> 128                             view_name = callback.__class__.__name__ + 
> '.__call__' # If it's a class
> 129                         raise ValueError("The view %s.%s didn't return 
> an HttpResponse object." % (callback.__module__, view_name))
> 130
> 131                     # If the response supports deferred rendering, 
> apply template
> 132                     # response middleware and the render the response
> 133  ->                 if hasattr(response, 'render') and 
> callable(response.render):
> 134                         for middleware_method in 
> self._template_response_middleware:
> 135                             response = middleware_method(request, 
> response)
> 136                         response = response.render()
> 137
> 138                 except http.Http404, e:
> (Pdb) n
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(183)get_response()
> -> urlresolvers.set_urlconf(None)
> (Pdb) l
> 178                     
> signals.got_request_exception.send(sender=self.__class__, request=request)
> 179                     response = self.handle_uncaught_exception(request, 
> resolver, sys.exc_info())
> 180             finally:
> 181                 # Reset URLconf for this thread on the way out for 
> complete
> 182                 # isolation of request.urlconf
> 183  ->             urlresolvers.set_urlconf(None)
> 184
> 185             try:
> 186                 # Apply response middleware, regardless of the response
> 187                 for middleware_method in self._response_middleware:
> 188                     response = middleware_method(request, response)
> (Pdb) n
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(185)get_response()
> -> try:
> (Pdb) n
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(187)get_response()
> -> for middleware_method in self._response_middleware:
> (Pdb) n
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(188)get_response()
> -> response = middleware_method(request, response)
> (Pdb) n
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(187)get_response()
> -> for middleware_method in self._response_middleware:
> (Pdb)
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(188)get_response()
> -> response = middleware_method(request, response)
> (Pdb)
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(187)get_response()
> -> for middleware_method in self._response_middleware:
> (Pdb)
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(188)get_response()
> -> *response = middleware_method(request, response)*
> (Pdb)
> *DatabaseError: Database...ne away'*)
> > 
> c:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py(188)get_response()
>
> The interesting thing about this is that it only happens in the one view.
>
> I have tried to fix it by restarting MySQL but it didn't help. I checked 
> the error log and there was nothing in there to indicate a problem occurred.
>
> I'm at a loss as what to do next.
>
> If anyone can make a suggestion I'd love to hear it.
>
> Thanks,
> /Paul
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to