Created
January 17, 2013 14:00
-
-
Save azyobuzin/4556069 to your computer and use it in GitHub Desktop.
pixiv_proxy
This file contains hidden or 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
#!/virtual/azyobuzin/local/bin/python | |
# -*- coding: utf-8 -*- | |
import cgitb | |
cgitb.enable() | |
import sys | |
sys.path.append("resolvers") | |
import cookielib | |
import os | |
import urllib2 | |
import urlparse | |
from private_constant import * | |
query = urlparse.parse_qs(os.environ.get("QUERY_STRING", "")) | |
if "uri" not in query: | |
print "Status: 400" | |
print "Content-Type: text/plain; charset=utf-8" | |
print "\"uri\" parameter is required." | |
exit() | |
jar = cookielib.CookieJar() | |
jar.set_cookie(cookielib.Cookie( | |
None, "PHPSESSID", pixivSessId, "80", "80", ".pixiv.net", None, None, "/", None, False, False, None, None, None, None | |
)) | |
req = urllib2.Request(query["uri"][0]) | |
jar.add_cookie_header(req) | |
try: | |
res = urllib2.urlopen(req) | |
except urllib2.HTTPError as ex: | |
res = ex | |
print "Status: " + str(res.code) | |
print "Content-Type: " + res.headers["content-type"] | |
sys.stdout.write(res.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment