Oauthlib: populate_token_attributes() 浮点值的 ValueError expires_at 值

创建于 2020-12-10  ·  7评论  ·  资料来源: oauthlib/oauthlib

https://github.com/oauthlib/oauthlib/blob/d54965b86ce4ede956db70baff0b3d5e9182a007/oauthlib/oauth2/rfc6749/clients/base.py#L516

某些标记具有expires_at值作为浮点数(例如: 1612807300.1613762 ),这会导致此行抛出ValueError: invalid literal for int() with base 10 。 这可以使用int(float(response.get('expires_at'))) (或四舍五入以不截断)来解决。

Bug Contributor Friendly OAuth2-Client

最有用的评论

expires_at的用法在 RFC 中没有定义,所以代码中似乎也很混乱。 我们可以假设它是一个类似于expires_in的 int 。

欢迎任何修复其用法并添加单元测试以覆盖此边缘情况的 PR。

所有7条评论

就在self._expires_at之上是一个浮点数:

self._expires_at = time.time() + int(self.expires_in)

expires_at的用法在 RFC 中没有定义,所以代码中似乎也很混乱。 我们可以假设它是一个类似于expires_in的 int 。

欢迎任何修复其用法并添加单元测试以覆盖此边缘情况的 PR。

嘿,我可以有这个问题吗? 我刚刚开始使用开源,所以这将是一个好的开始。

嘿,我可以有这个问题吗? 我刚刚开始使用开源,所以这将是一个好的开始。

@default-303 去吧!

@ggiill谢谢,我做了以下更改

- self._expires_at = int(response.get('expires_at')) 
+ self._expires_at = round(float(response.get('expires_at')))

并通过所有测试是当我运行pytest

但是你想让我添加什么样的测试? 就像一个简单的typecheck测试这样的 -
``
导入单元测试
import fix ## 我为这个演示编写的示例脚本
导入时间

类 TestFix(unittest.TestCase) :

def test_float(self) : 
    string_time = str(time.time())
    self.assertIsInstance(fix.get_time("123345.1222"), int)

def test_int(self) : 
    string_time = str(round(time.time()))
    self.assertIsInstance(fix.get_time("12333"), int)

``

还是完整的mock test

@ggiill嘿,我可以得到评论吗?
lmao 已经一个月了,即使我忘记了。

@ggiill嘿,我可以得到评论吗?
lmao 已经一个月了,即使我忘记了。

@default-303 我不是维护者 - ping @JonathanHuot。 您可能还想提交 PR 以供审查。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

JonathanHuot picture JonathanHuot  ·  10评论

ib-lundgren picture ib-lundgren  ·  21评论

JonathanHuot picture JonathanHuot  ·  15评论

ViktorHaag picture ViktorHaag  ·  11评论

JonathanHuot picture JonathanHuot  ·  26评论