Why am I getting an interrupt error when adding data to the database?

Not sure if there is a better way to do this, but I have a page to register on my site, and after the user signs up, I add my original data (material in the __init__ data model), then I start adding some other info to the same section that gives me a broken pipe error. Oddly enough, the code works because the records I expect are in the database. I tried navigating the .flush() command to see if it helps, but that doesn't seem to be the case.

 Traceback (most recent call last): File "/Users/me/Dropbox/code/eclipseWorkSpace/website/pyramidwiki/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/channel.py", line 134, in handle_write flush() File "/Users/me/Dropbox/code/eclipseWorkSpace/website/pyramidwiki/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/channel.py", line 249, in _flush_some num_sent = self.send(chunk) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py", line 365, in send result = self.socket.send(data) error: [Errno 32] Broken pipe 

Here is my code:

 if 'form.submitted' in request.params: firstname = request.params['firstname'] lastname = request.params['lastname'] email = request.params['email'] password = request.params['password'] try: new_user = Users(email, firstname, lastname, password) DBSession.add(new_user) #DBSession.flush() #commit so we get error if any #add some other info user_data = DBSession.query(Users).filter(Users.email==email).first() user_data.join_date = datetime.datetime.now() #create random number for verification url user_data.vertified = id_generator(50) DBSession.flush() #doesn't seem to make a difference where the flush is return HTTPFound(location = request.route_url('new')) 

Any ideas?

+4
source share
2 answers

This may not answer your question directly, but "you are doing everything wrong" (tm) :)

You do not need to re-query the User object after adding it to the session - what else, trying to request it from the database without executing session.flush () will first result in an error because there is no entry in the database. I would do something like this:

 if 'form.submitted' in request.params: firstname = request.params['firstname'] lastname = request.params['lastname'] email = request.params['email'] password = request.params['password'] try: new_user = Users(email, firstname, lastname, password) new_user.join_date = datetime.datetime.now() new_user.verified = id_generator(50) DBSession.add(new_user) DBSession.flush() # should fail if user email is in the database return HTTPFound(location = request.route_url('new')) 

In addition, you need to check that all execution branches (i.e. the except: else clause: the "if" form.submitted clause in request.params "return something meaningful", you can get an exception because your function viewing returns None in some conditions, in fact, something may have happened - the line user_data = DBSession.query (Users) "raised an exception", and the function except :, returned nothing

+2
source

I also struggled with the same problem in my Pyramid project and contrary to the comments on github, it was not with waitress .

In my case, the Error: Broken Pipe problem only occurred when I used redirects ( HTTPFound , HTTPMovedPermanently , etc.). Since your function also uses HTTPFound , I think the problem is the same.

At least for me this error is caused by the pyramid_debugtoolbar extension. The reason is probably because whenever our gaze does something like

return HTTPFound(foo)

it sends 302 in the header and Connection:Close . The pyramid_debugtoolbar adds a long body to the response. The client sees the header, closes the connection, and does not accept a long debugging body. Hence the Broken Pipe message (perhaps this is what Wireshark shows).

Try disabling pyramid_debugtoolbar in your .ini application, this may help.

+2
source

All Articles