Skip to content

Instantly share code, notes, and snippets.

Last active December 17, 2023 06:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save creke/c5a8a18fa41b8f5c1a0719a7e0cf4de6 to your computer and use it in GitHub Desktop.
Save creke/c5a8a18fa41b8f5c1a0719a7e0cf4de6 to your computer and use it in GitHub Desktop.
EarthLiveSharp 清理cloudinary CDN缓存
# -*- coding: utf-8 -*-
# Author: Creke
# HomePage:
import sys
import urllib, urllib2
import base64
import json
def Dict2Uri(dic):
return urllib.urlencode(dic)
def GenUrllibReq(url, method, api_key, api_secret, post_data=None):
urlreq = None
if post_data is None:
urlreq = urllib2.Request(url)
urlreq = urllib2.Request(url, post_data)
urlreq.get_method = lambda: method
auth_str = base64.b64encode('%s:%s' % (api_key, api_secret))
urlreq.add_header("Authorization", "Basic %s" % auth_str)
urlreq.add_header('Cache-Control', 'no-cache')
return urlreq
def GetApiDelUrl(cloud_name, img_type):
url = "" % (cloud_name, img_type)
params = {"prefix": "http://himawari8-dl"}
url = url + "?" + Dict2Uri(params)
return url
def main(argv):
arg_idx = 1
api_key = argv[arg_idx]
arg_idx += 1
api_secret = argv[arg_idx]
arg_idx += 1
cloud_name = argv[arg_idx]
while True:
del_url = GetApiDelUrl(cloud_name, 'fetch')
urlreq = GenUrllibReq(del_url, 'DELETE', api_key, api_secret)
print "==========================="
print "Requesting %s" % (del_url)
opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=URLLIB_DEBUG_LEVEL))
urllib_open =, timeout=URLLIB_TIMEOUT)
response =
print "==========================="
print "Response:"
print "%s" % (response)
print "==========================="
print "Done Requesting"
res_json = json.loads(response)
deleted_cnt = len(res_json['deleted'])
print "Deleted %u himawari8 pics" % (deleted_cnt)
print "==========================="
if 'next_cursor' in res_json and deleted_cnt>0:
print "Due to Cloudinary limits, we're starting a new round"
return 0
def PrintHelp(argv):
print "\t USAGE: %s [api_key] [api_secret] [cloud_name]" % (argv[0])
if __name__ == '__main__':
if len(sys.argv) < 4:
print "RUNNING main"
print "DONE main"
# -*- coding: utf-8 -*-
# Author: Creke
# HomePage:
from distutils.core import setup
import py2exe
Copy link

li360 commented Mar 16, 2017


reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Cache-Control: no-cache
header: Content-Type: application/json; charset=utf-8
header: Date: Thu, 16 Mar 2017 05:40:34 GMT
header: Server: cloudinary
header: Status: 401 Unauthorized
header: WWW-Authenticate: Basic realm="Cloudinary"
header: X-Cld-Error: disabled account
header: X-Request-Id: a1b8a7f3e076c220
header: X-UA-Compatible: IE=Edge,chrome=1
header: Content-Length: 40
header: Connection: Close
Traceback (most recent call last):
File "", line 77, in
File "", line 49, in main
File "urllib2.pyc", line 437, in open
File "urllib2.pyc", line 550, in http_response
File "urllib2.pyc", line 475, in error
File "urllib2.pyc", line 409, in _call_chain
File "urllib2.pyc", line 558, in http_error_default
urllib2.HTTPError: HTTP Error 401: Unauthorized


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment