message = Message()
message.body = messageParts
message.whoFrom = conv.name
- message.when = conv.time.strftime("%I:%M %p")
+ try:
+ message.when = conv.time.strftime("%I:%M %p")
+ except ValueError:
+ _moduleLogger.exception("Confusing time provided: %r" % conv.time)
+ message.when = "Unknown"
conv.messages = (message, )
yield conv
def _parse_with_validation(self, page):
json = parse_json(page)
- validate_response(json)
+ self._validate_response(json)
return json
+ def _validate_response(self, response):
+ """
+ Validates that the JSON response is A-OK
+ """
+ try:
+ assert response is not None, "Response not provided"
+ assert 'ok' in response, "Response lacks status"
+ assert response['ok'], "Response not good"
+ except AssertionError:
+ try:
+ if response["data"]["code"] == 20:
+ raise RuntimeError(
+"""Ambiguous error 20 returned by Google Voice.
+Please verify you have configured your callback number (currently "%s"). If it is configured some other suspected causes are: non-verified callback numbers, and Gizmo5 callback numbers.""" % self._callbackNumber)
+ except KeyError:
+ pass
+ raise RuntimeError('There was a problem with GV: %s' % response)
+
_UNESCAPE_ENTITIES = {
""": '"',
return jsonTree, flatHtml
-def validate_response(response):
- """
- Validates that the JSON response is A-OK
- """
- try:
- assert response is not None
- assert 'ok' in response
- assert response['ok']
- except AssertionError:
- raise RuntimeError('There was a problem with GV: %s' % response)
-
-
def guess_phone_type(number):
if number.startswith("747") or number.startswith("1747") or number.startswith("+1747"):
return GVoiceBackend.PHONE_TYPE_GIZMO