bitly URL shortener中的连接超时错误

时间:2013-10-21 16:28:39

标签: python url-shortener

我正在尝试使用bitly-api-python library来缩短数组中的所有网址。

def bitly3_shorten_oauth(url):
    c = bitly3.Connection(access_token= bitly_access_token)
    sh = c.shorten(url)
    return sh['url']

for i in arr:
    print i[1] , bitly3_shorten_oauth(i[1])

我一个接一个地打电话给他们而没有任何超时,因为我在best practices documentation of bitly中找不到任何此类预防措施。

以下是我的完整代码,请查看:http://pastie.org/8419004

但正在发生的是它缩短了2个或3个网址,然后进入连接超时错误

connection timeout error

可能导致此错误的原因以及如何调试?

3 个答案:

答案 0 :(得分:0)

来自您关联的文档:

bitly currently institutes per-hour, per-minute, 
and per-IP rate limits for each API method

并且

High-Volume Shorten Requests
If you need to shorten a large number of URLs at once, we recommend that 
you leave ample time to spread these requests out over many hours. Our API 
rate limits reset hourly, and rate limited batch requests can be resumed at 
the top of the hour.

所以看起来你只需要放慢代码速度。

答案 1 :(得分:0)

如果有人发现这个过时的帖子作为起点,请注意,当今Bit.ly API拒绝非OAuth API密钥。

在python中获取带有curl的API密钥:

    companies   labels
0   9           7
1   1           4
2   6           7
3   1           1
4   8           5

Doc link

答案 2 :(得分:0)

截至2019年,有bitlyshortener软件包,尽管它仅适用于Python≥3.7。我使用它没有遇到任何错误。