THRIFT-4370: build generated code before running static code analysis;
fix E722 flake8 issues identified in python code

This closes #1399
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index a7366a8..04ad62a 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -193,7 +193,7 @@
     try:
         pfactory.string_length_limit = options.string_limit
         pfactory.container_length_limit = options.container_limit
-    except:
+    except Exception:
         # Ignore errors for those protocols that does not support length limit
         pass
 
@@ -255,7 +255,7 @@
                     logging.info('Requesting server to stop()')
                 try:
                     server.stop()
-                except:
+                except Exception:
                     pass
             signal.signal(signal.SIGALRM, clean_shutdown)
             signal.alarm(4)
diff --git a/test/py/TestSocket.py b/test/py/TestSocket.py
index ae3160f..619eb10 100755
--- a/test/py/TestSocket.py
+++ b/test/py/TestSocket.py
@@ -36,7 +36,7 @@
                 self.listen_sock.bind(('localhost', self.port))
                 self.listen_sock.listen(5)
                 break
-            except:
+            except Exception:
                 if i == 49:
                     raise
 
@@ -50,7 +50,7 @@
                 socket.setTimeout(10)
                 socket.open()
                 leaky.append(socket)
-        except:
+        except Exception:
             self.assert_(time.time() - starttime < 5.0)
 
     def testWriteTimeout(self):
@@ -64,7 +64,7 @@
             while True:
                 lsock.write("hi" * 100)
 
-        except:
+        except Exception:
             self.assert_(time.time() - starttime < 5.0)