Skip to content

Instantly share code, notes, and snippets.

@xixitalk
Last active December 13, 2015 20:28
Show Gist options
  • Save xixitalk/4969986 to your computer and use it in GitHub Desktop.
Save xixitalk/4969986 to your computer and use it in GitHub Desktop.
为flask_twip添加图片代理
def getimg(self):
imgurl = request.args.get('imgurl','')
if len(imgurl) == 0:
return '<form action="/twip/getimg" method="get"><input type="text" size="50" name="imgurl" /> <input type="submit" value="submit" />'
urlobj = urllib2.urlopen(imgurl)
header = urlobj.info()
headers = {}
headers['Content-Type'] = header.get('Content-Type','image/png')
content = urlobj.read()
status = urlobj.getcode()
respon = make_response((content,status,headers))
return respon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment