newsdev / who-the-hill

Who The Hill: An MMS-based facial recognition service for members of Congress.
Other
222 stars 15 forks source link

No "failure message" for non-Congresspersons #9

Open SHewitt95 opened 7 years ago

SHewitt95 commented 7 years ago

twilio_app.py runs into this error when non-Congresspersons are sent in:

Traceback (most recent call last):
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1614, in full_dispatch_reque
st
    rv = self.handle_user_exception(e)
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1517, in handle_user_excepti
on
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1612, in full_dispatch_reque
st
    rv = self.dispatch_request()
  File "C:\Users\Sherman\DOCUME~1\PROGRA~1\Github\WHO_TH~1\lib\site-packages\flask\app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Sherman\Documents\Programming Projects\Github\who_the_hill\twilio_app.py", line 170, in recongize
    del target_image
UnboundLocalError: local variable 'target_image' referenced before assignment

...which results in no response from Twilio. Congresspeople do elicit a Twilio response, as expected. Images without recognized faces trigger a "failure message," as expected.

Example: Send in picture of Marco Rubio, get back Marco Rubio and image. Example: Send in picture of a chair, get back failure message. Example: Send in picture of Will Smith, get back nothing.

SHewitt95 commented 7 years ago

It seems to have something to do with an earlier del statement: https://github.com/newsdev/who_the_hill/blob/master/twilio_app.py#L152

Commenting out that line allowed the failure message to send.

SHewitt95 commented 7 years ago

Looks like this line still executes even if we hit this prior section, thus causing the error. Removing the first del fixes the issue.

Fun fact: finally will always execute, regardless of what's in the try block.