Advertisement
lamiastella

ImgurClientRateLimitError: Rate-limit exceeded

Oct 18th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.35 KB | None | 0 0
  1. 18 image_type = ['jpg', 'jpeg', 'png', 'gif']
  2.  19
  3.  20 imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token)
  4.  21
  5.  22
  6.  23 timeTillUserReset = imgur_client.credits['UserReset']#Grabs the time the user quota will reset in Unix Epoch
  7.  24 timeString = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(float(timeTillUserReset)))#Formats the Unix Epoch to something readable
  8.  25 print ('User Limit: ' + str(imgur_client.credits['UserLimit']))#Print the Total credits that can be allocated.
  9.  26 print ('User Remaining: ' + str(imgur_client.credits['UserRemaining']))#Print Total credits available.
  10.  27 print ('User Reset: ' + str(timeString)) #Timestamp for when the credits will be reset.
  11.  28 print ('User Client Limit: ' + str(imgur_client.credits['ClientLimit'])) #Total credits that can be allocated for the application in a day.
  12.  29 print ('User Client Remaining: ' + str(imgur_client.credits['ClientRemaining'])) #Total credits remaining for the application in a day.
  13.  30
  14.  31 item_count = 0
  15.  32 #p=0
  16.  33 #for p in range(1, 1000):
  17.  34 #for p in range(100, -1, -1):
  18.  35 p=0
  19.  36 while True:
  20.  37     p += 1
  21.  38     time.sleep(3)
  22.  39     try:
  23.  40         search = imgur_client.gallery_search('horse', window='all', sort='viral', page=p)
  24.  41         for i in range(0, len(search)):
  25.  42             item_count +=1
  26.  43             print(search[i].comment_count)
  27.  44             if not search[i].is_album:
  28.  45                 print(search[i].type)
  29.  46             print('{0}: {1}'.format("page number is", p))
  30.  47             if search[i].comment_count > 10 and not search[i].is_album:
  31.  48                 if search[i].type[6:] in image_type:
  32.  49                     count = 0
  33.  50                     try:
  34.  51                         image_file = urllib2.urlopen(search[i].link, timeout = 5)
  35.  52                         image_file_name = 'images/'+ search[i].id+'.'+search[i].type[6:]
  36.  53                         output_image = open(image_file_name, 'wb')
  37.  54                         output_image.write(image_file.read())
  38.  55                         for post in imgur_client.gallery_item_comments(search[i].id, sort='best'):
  39.  56                             if count <= 10:
  40.  57                                 count += 1
  41.  58                         output_image.close()
  42.  59                     except urllib2.URLError as e:
  43.  60                         print(e)
  44.  61                         continue
  45.  62                     except socket.timeout as e:
  46.  63                         print(e)
  47.  64                         continue
  48.  65                     except socket.error as e:
  49.  66                         print(e.status_code)
  50.  67                         print(e.error_code)
  51.  68                         continue
  52.  69     except ImgurClientError as e:
  53.  70         print(e.status_code)
  54.  71         print(e.error_message)
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. --------------------------------------
  68.  
  69. image/jpeg
  70. page number is: 22
  71. /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.
  72.   InsecurePlatformWarning
  73. 4
  74. image/gif
  75. page number is: 22
  76. 5
  77. image/jpeg
  78. page number is: 22
  79. 9
  80. page number is: 22
  81. 13
  82. image/gif
  83. page number is: 22
  84. /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.
  85.   InsecurePlatformWarning
  86. Traceback (most recent call last):
  87.   File "download.py", line 55, in <module>
  88.     for post in imgur_client.gallery_item_comments(search[i].id, sort='best'):
  89.   File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 564, in gallery_item_comments
  90.     response = self.make_request('GET', 'gallery/%s/comments/%s' % (item_id, sort))
  91.   File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 153, in make_request
  92.     raise ImgurClientRateLimitError()
  93. imgurpython.helpers.error.ImgurClientRateLimitError: Rate-limit exceeded!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement