0

每次调用迭代器时,我都使用github3.py传递参数,例如:etag

user.iter_starred(etag='97ba89b5c009e5530f108a06606f3e2c')

为了避免消耗我的速率限制并执行条件请求。但无论如何,当我开始迭代时,github3 总是执行正确的请求(因此获取真实数据),将速率限制降低 1。

我做错了什么还是一个错误?

4

1 回答 1

0

根据我自己的实验,这似乎按预期工作:

>>> import github3
>>> u = github3.user('sigmavirus24')
>>> u
<User [sigmavirus24:Ian Cordasco]>
>>> i = u.iter_starred()
>>> i
<GitHubIterator [-1, /users/sigmavirus24/starred]>
>>> next(i)
<Repository [functional-koans/clojure-koans]>
>>> i.etag
'"1aeaaa7a249610c52ba0363009afcab9"'
>>> next(u.iter_starred(etag=i.etag))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "github3/structs.py", line 103, in next
    return self.__next__()
  File "github3/structs.py", line 90, in __next__
    return next(self.__i__)
StopIteration

我们的示例之间的区别在于您的 etag 值是'97ba89b5c009e5530f108a06606f3e2c',而与我的等价物是'"97ba89b5c009e5530f108a06606f3e2c"'。由于这个值被放在标题中,我认为标题是很重要的:

If-None-Match: "97ba89b5c009e5530f108a06606f3e2c"

代替:

If-None-Match: 97ba89b5c009e5530f108a06606f3e2c

这是您将发送的内容。

我刚刚检查了一下,这就是问题所在。图书馆按预期工作。您传递 etag 值的方式是错误的。它需要在值周围加上双引号(例如,'"97ba89b5c009e5530f108a06606f3e2c"')才能正常工作。

于 2014-03-28T18:14:01.880 回答