douban.py 472 B

1234567891011121314151617
  1. import json
  2. from oauthlib.common import to_unicode
  3. def douban_compliance_fix(session):
  4. def fix_token_type(r):
  5. token = json.loads(r.text)
  6. token.setdefault("token_type", "Bearer")
  7. fixed_token = json.dumps(token)
  8. r._content = to_unicode(fixed_token).encode("utf-8")
  9. return r
  10. session._client_default_token_placement = "query"
  11. session.register_compliance_hook("access_token_response", fix_token_type)
  12. return session