mailchimp.py 679 B

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