本文介绍了imgurpython.helpers.error.ImgurClientRateLimitError:超出了速率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有以下错误:/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarningTraceback (most recent call last): File "download.py", line 22, in <module> search = imgur_client.gallery_search('cat', window='all', sort='time', page=p) File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 531, in gallery_search response = self.make_request('GET', 'gallery/search/%s/%s/%s' % (sort, window, page), data) File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 153, in make_request raise ImgurClientRateLimitError()imgurpython.helpers.error.ImgurClientRateLimitError: Rate-limit exceeded!: 1 from imgurpython import ImgurClient 2 import inspect 3 import random 4 import urllib2 5 import requests 6 from imgurpython.helpers.error import ImgurClientError 7 8 client_id = "ABC" 9 client_secret = "ABC" 10 access_token = "ABC" 11 refresh_token = "ABC" 12 13 14 15 image_type = ['jpg', 'jpeg'] 16 17 imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token) 18 19 item_count = 0 20 for p in range(1, 10000): 21 try: 22 search = imgur_client.gallery_search('cat', window='all', sort='time', page=p) 23 for i in range(0,https://gist.github.com/monajalal/e02792e9a5cbced301a8691b7a62836f len(search)): 24 item_count +=1 25 print(search[i].comment_count) 26 if search[i].comment_count > 10 and not search[i].is_album: 27 print(search[i].type) 28 if search[i].type[6:] in image_type: 29 count = 0 30 try: 31 image_file = urllib2.urlopen(search[i].link, timeout = 5) 32 image_file_name = 'images/'+ search[i].id+'.'+search[i].type[6:] 33 output_image = open(image_file_name, 'wb') 34 output_image.write(image_file.read()) 35 for post in imgur_client.gallery_item_comments(search[i].id, sort='best'): 36 if count <= 10: 37 count += 1 38 output_image.close() 39 except urllib2.URLError as e: 40 print(e) 41 continue 42 except socket.timeout as e: 43 print(e) 44 continue 45 except socket.error as e: 46 print(e) 47 continue 48 except ImgurClientError as e: 49 print(e) 50 continue 51 52 print item_count此外,我几乎经常看到这一行:Also I see this line almost very often:/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning如何修复错误? Imgur中的速率限制错误是否有任何解决方法?所以我正在创建这个应用程序,用于学术研究,不用于商业和 https://api.imgur.com/ #limits 它应该是免费的,但我必须注册我的应用程序以获取与client_id相关的东西。如何将我的应用程序设置为非商业应用程序,以便我不会收到此速率限制错误,或者如果所有类型的应用程序都出现此错误,我应该如何处理它?我应该如何设置我的代码,以便每小时只发出1250个请求?How can I fix the error? Is there any workaround for rate limit error in Imgur? So I am creating this app for academic research use not for commercial and according to https://api.imgur.com/#limits it should be free but I had to register my app to get client_id related stuff. How can I set my application as non-commercial so that I would not get this rate limit error or if all kind of applications get this error how should I handle it? How should I set my code so that it would make only 1250 requests per hour?此处还有我的信用信息:Also here's my credit info:User Limit: 500User Remaining: 500User Reset: 2016-10-18 14:32:41User Client Limit: 12500User Client Remaining: 9570更新:按照答案中的建议使用sleep(8)我最终会继续这样做。对于不同的搜索查询,这发生在不同的页面。如何修复代码,以便在发生这种情况时停止执行?以下是此更新的相关代码: https://gist.github.com/monajalal/e02792e9a5cbced301a8691b7a62836f UPDATE: With sleep(8) as suggested in the answer I end up with this going on continuously. For different search query this happens at different pages. How can I fix the code so that it would stop executing when this happens? Here's the related code to the update: https://gist.github.com/monajalal/e02792e9a5cbced301a8691b7a62836fpage number is: 1570image/jpegpage number is: 1570page number is: 1570page number is: 157/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning 推荐答案费率限制是指如何您经常使用API,而不是允许多少次通话。为防止锤击,大多数API都有速率限制(例如:每分钟30个请求,每2秒1个)。你的脚本尽可能快地发出请求,比限制快几百甚至几千倍。The rate limit refers to how frequently you're hitting the API, not how many calls you're allowed. To prevent hammering, most APIs have a rate limit (eg: 30 requests per minute, 1 every 2 seconds). Your script is making requests as quickly possible, hundreds or even thousands of times faster than the limit.为了防止你的脚本被锤击,最简单的解决方案是引入一个 sleep 到你的for循环。To prevent your script from hammering, the simplest solution is to introduce a sleep to your for loop.from time import sleepfor i in range(10000): print i sleep(2) # seconds调整睡眠时间为比API定义的速率限制至少大一秒。Adjust the sleep time to be at least one second greater than what the API defines as its rate limit. https://api.imgur.com/#limits Imgur API使用信用分配系统确保公平分配能力。每个应用程序每天允许大约1,250次上传或每天大约12,500次请求。如果每月限制在一个月内达到五次,则该应用程序将在该月剩余时间内被阻止。剩余的信用额度将在 X-RateLimit-ClientRemaining HTTP标头中的每个请求响应中显示。 The Imgur API uses a credit allocation system to ensure fair distribution of capacity. Each application can allow approximately 1,250 uploads per day or approximately 12,500 requests per day. If the daily limit is hit five times in a month, then the app will be blocked for the rest of the month. The remaining credit limit will be shown with each requests response in the X-RateLimit-ClientRemaining HTTP header.所以12500个请求/ 24小时是每小时520个请求或每分钟大约8个请求。这意味着你的睡眠时间应该是8秒左右。So 12500 requests / 24 hours is 520 requests per hour or ~8 per minute. That means your sleep should be about 8 seconds long. 这篇关于imgurpython.helpers.error.ImgurClientRateLimitError:超出了速率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-22 07:26