mailchimp.py 757 B

1234567891011121314151617181920212223
  1. import json
  2. from oauthlib.common import to_unicode
  3. def mailchimp_compliance_fix(session):
  4. def _null_scope(r):
  5. token = json.loads(r.text)
  6. if "scope" in token and token["scope"] is None:
  7. token.pop("scope")
  8. r._content = to_unicode(json.dumps(token)).encode("utf-8")
  9. return r
  10. def _non_zero_expiration(r):
  11. token = json.loads(r.text)
  12. if "expires_in" in token and token["expires_in"] == 0:
  13. token["expires_in"] = 3600
  14. r._content = to_unicode(json.dumps(token)).encode("utf-8")
  15. return r
  16. session.register_compliance_hook("access_token_response", _null_scope)
  17. session.register_compliance_hook("access_token_response", _non_zero_expiration)
  18. return session