Created
June 25, 2013 11:08
-
-
Save liuzhe0223/5857687 to your computer and use it in GitHub Desktop.
用于上传图片到 https://api.imgur.com , 返回图片url, 论坛发图片用的
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
import urllib2 | |
import urllib | |
import sys | |
import json | |
try: | |
data = file(sys.argv[1], 'r').read() | |
except: | |
print "please give a picture, and make sure your filename is correct" | |
exit() | |
urldata = urllib.urlencode({"image" : data}) | |
url = "https://api.imgur.com/3/upload" | |
r = urllib2.Request(url) | |
r.add_data(urldata) | |
r.add_header('Authorization','Client-ID 1c49486ec8e9565') | |
res = json.loads( urllib2.urlopen(r).read()) | |
print res['data']['link'] | |
#upload a picture to imgur, and return a link |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment