问题是,当我在开发环境(谷歌应用引擎的本地服务器)中使用 urlfetch.fetch(...) 执行 POST 请求时,我得到了 HTTP 302 状态,正如我所料(我可以进行重定向)。但是当我上传应用程序并尝试从 .appspot.com 运行它时,然后使用 403 获取响应,即“禁止”。
细节:
- 网址是 https(我的银行网站)
- 请求标头中有 cookie
- .. 还有什么 ?
看起来,远程站点(银行)以不同的方式看到 2 个请求:本地可以,“来自 goole”不可以。
我的python代码:
url1 = "https://www.ebgz.pl/detal-web/jbank/unlogged/choose/method.do?rid="+str(random.random())+"&srvc="
response = urlfetch.fetch(url1)
lparser = Link_HTMLParser()
lparser.feed(response.content)
url2 = "https://www.ebgz.pl" + lparser.frameSrc
hdrs = {}
hdrs['Referer'] = url1
cookie = response.headers.get('Set-Cookie')
if cookie:
hdrs['Cookie'] = cookie
response = urlfetch.fetch(url2, headers = hdrs)
Link_HTMLParser 是用于获取框架源链接的简单解析器(如果您查看 url1 的第一个响应内容,它就会变得清晰):
class Link_HTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == "iframe":
for n,v in attrs:
if n == 'src':
self.frameSrc = v
问题在于第二个响应:它的 403 来自谷歌,200 来自本地 gae serwer。我在问题的开头提到了一个 POST,但似乎无论使用哪种方法(GET 或 POST)都会出现问题。我猜这是一些会话管理问题..