3

我无法通过 Google App Engine 中的代理发出任何 HTTP POST 请求,使用 httplib(set_tunnel,似乎不支持:http ://code.google.com/p/googleappengine/source/browse/trunk/python/ google/appengine/dist27/httplib.py?r=281&spec=svn281)也不是 urllib2。

事实是,在本地测试中请求是否有效,至少返回一些东西,我不知道是通过代理还是直接(都使用 httplib(set_tunnel)和 urllib2),但是当我将更改上传到谷歌的服务器没有任何作用。

我用来提出请求的功能是:

def __urllib2Post(self, post_args, tokenizer):
    Post = urllib.urlencode(post_args, doseq=True)
    headers = {
                "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)", 
                #"Host": "servicios.mitele.es", 
                #"Accept-Encoding": "gzip", 
                "Accept-Charset": "ISO-8859-1,UTF-8;q=0.7,*;q=0.7", 
                "Referer": "http://static1.tele-cinco.net/comun/swf/playerMitele.swf",
                "Connection": "close", 
                "Accept-Language": "de,en;q=0.7,en-us;q=0.3", 
                "Content-type": "application/x-www-form-urlencoded"
                }
    url = "http://servicios.mitele.es" + tokenizer
    proxy_h = urllib2Local.ProxyHandler({"http" : "80.58.250.68:80"})
    opener = urllib2Local.build_opener(proxy_h)  
    urllib2Local.install_opener(opener)  
    req = urllib2Local.Request(url, Post, headers)
    response = urllib2Local.urlopen(req)
    return response.read()

def __post(self, post_args, tokenizer):
    Post = urllib.urlencode(post_args, doseq=True)
    headers = {
                "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)", 
                #"Host": "servicios.mitele.es", 
                #"Accept-Encoding": "gzip", 
                "Accept-Charset": "ISO-8859-1,UTF-8;q=0.7,*;q=0.7", 
                "Referer": "http://static1.tele-cinco.net/comun/swf/playerMitele.swf",
                "Connection": "close", 
                "Accept-Language": "de,en;q=0.7,en-us;q=0.3", 
                "Content-type": "application/x-www-form-urlencoded"
                }
    #conn = httplib.HTTPConnection("213.4.97.107", 80)
    conn = httplib.HTTPConnection("servicios.mitele.es", 80)
    conn.set_tunnel("80.58.250.68", 80, headers)
    conn.request("POST", tokenizer, Post, headers)
    response = conn.getresponse()

    #print response.status, response.reason
    if response.status == 404: #NOT FOUND
        data = None
    elif response.status == 400: #BAD REQUEST
        data = None
    else:
        data = response.read()
    conn.close()
    return data

我需要这样做,因为我有一个网站,可以找到主要西班牙电视台网站视频的下载链接,其中一些在地理上被锁定,我需要通过西班牙代理提出请求。我不能使用网络代理,因为请求必须是 POST 格式。

有没有办法通过 Google App Engine 中的代理进行 HTTP POST 请求?

非常感谢任何帮助..对不起我的英语。

4

0 回答 0