2016-10-18 2 views
0

나는 다음과 같은 오류가이 코드에 대한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. 
    InsecurePlatformWarning 
Traceback (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 

거의 자주이 줄을 참조하십시오

/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 건의 요청 만하도록 내 코드를 어떻게 설정해야합니까?

User Limit: 500 
User Remaining: 500 
User Reset: 2016-10-18 14:32:41 
User Client Limit: 12500 
User Client Remaining: 9570 

UPDATE :

또한 여기에 신용 정보의 수면 (8) 나는이 지속적으로 진행하여 결국이 질문에 대해 제안과 함께. 다른 검색 쿼리의 경우이 작업은 여러 페이지에서 발생합니다. 이 문제가 발생했을 때 실행을 중지하도록 코드를 수정하려면 어떻게해야합니까? 다음 업데이트에 관련된 코드는 다음과 같습니다 https://gist.github.com/monajalal/e02792e9a5cbced301a8691b7a62836f

page number is: 157 
0 
image/jpeg 
page number is: 157 
0 
page number is: 157 
0 
page 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 
+0

경고에 관해서는 새로운 질문을하십시오. – Soviut

답변

1

속도 제한 당신이 API를 타격하고 빈도를 말합니다, 당신은 허용하고 있지 통화 수. 해머링을 방지하기 위해 대부분의 API에는 속도 제한이 있습니다 (예 : 분당 30 건, 2 초마다 1 건). 스크립트는 제한보다 빨리, 수백 또는 수천 배 빠른 요청을합니다.

스크립트가 망치질되지 않게하려면 가장 간단한 해결책은 sleep을 for 루프에 도입하는 것입니다.

from time import sleep 

for i in range(10000): 
    print i 
    sleep(2) # seconds 

수면 시간을 API가 속도 제한으로 정의한 것보다 1 초 이상으로 조정하십시오.

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.

https://api.imgur.com/#limits

그래서 12500 개 요청/24 시간 5백20시간 당 요청이나 ~ 분당 8입니다. 즉, 수면은 약 8 초가되어야합니다.

+0

시간당 1250 건의 요청 만 할 수 있지만 시간이 얼마나 걸릴지 알고 있습니다. –

+0

나는 그것이 잠 (2)와 함께 나를 위해 일하고있는 것처럼 대답을 받아들입니다. 내가 같은 오류를 다시 본다면 나는 나중에 논평 할 것이다! 고마워요. –

+0

기회가 있다면주세요. http://stackoverflow.com/questions/40116518/only-limited-number-of-pages-can-be-retrieved –

관련 문제