New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new survivor: encoding error when avatar included in submission #413

Closed
toconnell opened this Issue Nov 16, 2017 · 5 comments

Comments

Projects
None yet
1 participant
@toconnell
Copy link
Owner

toconnell commented Nov 16, 2017

I've seen a bunch of these, but this one is especially simple, so we'll start the firefight here:

[59fff8038740d93bd3df6c56] was logged out of the webapp instance on ubuntu-trusty-1 due to a render failure at 2017-11-16 00:28:46.464705.

 The traceback from the exception was this:

Traceback (most recent call last):
File "/home/toconnell/kdm-manager/v1/session.py", line 64, in wrapper
 return func(self, *args, **kwargs)
File "/home/toconnell/kdm-manager/v1/session.py", line 502, in process_params
 response = api.post_JSON_to_route("/new/survivor", payload=POST_params, Session=self)
File "", line 2, in post_JSON_to_route
File "/usr/local/lib/python2.7/dist-packages/retry/api.py", line 74, in retry_decorator
 logger)
File "/usr/local/lib/python2.7/dist-packages/retry/api.py", line 33, in __retry_internal
 return f()
File "/home/toconnell/kdm-manager/v1/api.py", line 129, in post_JSON_to_route
 return requests.post(req_url, data=json.dumps(payload, cls=customJSONencoder), headers=h)
File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
 sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
 chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
 return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte
@toconnell

This comment has been minimized.

Copy link
Owner

toconnell commented Nov 27, 2017

Since I literally cannot figure out a way to replicate this, we're going to wrap it in a try/except so that it can maybe tell us when/how it fails.

@toconnell

This comment has been minimized.

Copy link
Owner

toconnell commented Nov 27, 2017

diff --git a/v1/api.py b/v1/api.py
index 2b10783..3385924 100755
--- a/v1/api.py
+++ b/v1/api.py
@@ -126,8 +126,12 @@ def post_JSON_to_route(route=None, payload={}, headers={}, Session=None):
     if headers != {}:
         h.update(headers)

-    return requests.post(req_url, data=json.dumps(payload, cls=customJSONencoder), headers=h, verify=False)
-
+    try:
+        return requests.post(req_url, data=json.dumps(payload, cls=customJSONencoder), headers=h, verify=False)
+    except Exception as e:
+        logger.error("api.post_JSON_to_Route() call failed! Exception caught while creating request object!")
+        logger.exception(e)
+        raise

@toconnell toconnell added the research label Dec 1, 2017

@toconnell

This comment has been minimized.

Copy link
Owner

toconnell commented Dec 4, 2017

ugh now the exception-capturing code is throwing an exception that obscures the error even further.

I am really bad at this.

diff --git a/v1/api.py b/v1/api.py
index fa13ddb..3645d1a 100755
--- a/v1/api.py
+++ b/v1/api.py
@@ -132,7 +132,7 @@ def post_JSON_to_route(route=None, payload={}, headers={}, Session=None):
         msg = "api.post_JSON_to_Route() call failed! Exception caught while creating request object!"
         logger.error(msg)
         logger.exception(e)
-        raise Exception("\n".join([msg, e, str(payload)]))
+        raise Exception("\n".join([msg, str(payload)]))
@toconnell

This comment has been minimized.

Copy link
Owner

toconnell commented Dec 8, 2017

Found it!

The issue is when a new survivor creation form is submitting and includes a survivor avatar!

Apparently that broke some time ago, and the intermittent occurrences of it are when users attempt to create a new one with an avatar.

From the refactored exception-capturing code:

[5a2a6a3d8740d94deda46b7c] was logged out of the webapp instance on ubuntu-trusty-1 due to a render failure at 2017-12-08 10:58:02.108281.

 The traceback from the exception was this:

Traceback (most recent call last):
File "/home/toconnell/kdm-manager/v1/session.py", line 64, in wrapper
 return func(self, *args, **kwargs)
File "/home/toconnell/kdm-manager/v1/session.py", line 502, in process_params
 response = api.post_JSON_to_route("/new/survivor", payload=POST_params, Session=self)
File "", line 2, in post_JSON_to_route
File "/usr/local/lib/python2.7/dist-packages/retry/api.py", line 74, in retry_decorator
 logger)
File "/usr/local/lib/python2.7/dist-packages/retry/api.py", line 33, in __retry_internal
 return f()
File "/home/toconnell/kdm-manager/v1/api.py", line 135, in post_JSON_to_route
 raise Exception("\n".join([msg, str(payload)]))
Exception: api.post_JSON_to_Route() call failed! Exception caught while creating request object!
{'email': 'REDACTED', 'survivor_avatar': '\xff\xd8\xff\xe1\x1d7Exif\x00\x00MM\x00*\x00\x00\x00\x08\x00\x0c\x01\x00\x00\x03\x00\x00\x00\x01\x02g\x00\x00\x01\x01\x00\x03\x00\x00\x00\x01\x01\x9a\x00\x00\x01\x02\x00\x03\x00\x00\x00\x03\x00\x00\x00\x9e\x01\x06\x00\x03\x00\x00\x00\x01\x00\x02\x00\x00\x01\x12\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01\x15\x00\x03\x00\x00\x00\x01\x00\x03\x00\x00\x01\x1a\x00\x05\x00\x00\x00\x01\x00\x00\x00\xa4\x01\x1b\x00\x05\x00\x00\x00\x01\x00\x00\x00\xac\x01(\x00\x03\x00\x00\x00\x01\x00\x02\x00\x00\x011\x00\x02\x00\x00\x00\x1f\x00\x00\x00\xb4\x012\x00\x02\x00\x00\x00\x14\x00\x00\x00\xd3\x87i\x00\x04\x00\x00\x00\x01\x00\x00\x00\xe8\x00\x00\x01 \x00\x08\x00\x08\x00\x08\x00\n\xfc\x80\x00\x00\'\x10\x00\n\xfc\x80\x00\x00\'\x10Adobe Photoshop CC (Macintosh)\x002017:12:08 11:57:07\x00\x00\x00\x04\x90\x00\x00\x07\x00\x00\x00\x040221\xa0\x01\x00\x03\x00\x00\x00\x01\xff\xff\x00\x00\xa0\x02\x00\x04\x00\x00\x00\x01\x00\x00\x01\xb6\xa0\x03\x00\x04\x00\x00\x00\x01\x00\x00\x01\x9a\x00\x00\x00\x00\x00\x00\x00\x06\x01\x03\x00\x03\x00\x00\x00\x01\x00\x06\x00\x00\x01\x1a\x00\x05\x00\x00\x00\x01\x00\x00\x01n\x01\x1b\x00\x05\x00\x00\x00\x01\x00\x00\x01v\x01(\x00\x03\x00\x00\x00\x01\x00\x02\x00\x00\x02\x01\x00\x04\x00\x00\x00\x01\x00\x00\x01~\x02\x02\x00\x04\x00\x00\x00\x01\x00\x00\x1b\xb1\x00\x00\x00\x00\x00\x00\x00H\x00\x00\x00\x

@toconnell toconnell changed the title API: encoding error from legacy webapp Create new survivor: encoding error when avatar included in submission Dec 8, 2017

@toconnell

This comment has been minimized.

Copy link
Owner

toconnell commented Dec 8, 2017

OK, this is fixed in the next release (which pushes avatar support to the API).

@toconnell toconnell closed this Dec 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment