【问题标题】:Cookie for Google App Engine request - Python用于 Google App Engine 请求的 Cookie - Python
【发布时间】:2014-03-24 15:00:49
【问题描述】:

我正在开发一个使用 API 的应用程序,该 API 要求我发出第一个 Post 请求以进行身份​​验证。

查看身份验证响应,我看到创建了一个 cookie:ApiCredentials=....

所以我验证了:

result = urlfetch.fetch(url = url, method = urlfetch.POST)
api_credential = result.headers['set-cookie']

然后我在标头中使用该 cookie 创建一个请求

urlfetch.fetch(url = url, method = urlfetch.GET, headers = {'Cookie': api_credential})

问题是:在开发中一切正常,但是当我部署时,它不起作用。在日志中我可以看到收到的 cookie。

API 链接:http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1(葡萄牙语)

【问题讨论】:

    标签: python google-app-engine cookies


    【解决方案1】:

    问题中的代码未显示 cookie 名称 ApiCredentials。可能在开发中只有一个 cookie,而在生产中有更多,在这种情况下 result.headers['set-cookie'] 返回多个值,以逗号分隔。

    URL Fetch Response Objects 页面建议通过调用 result.header_msg.getheaders('set-cookie') 来检索列表中的多个同名标头,然后在结果列表中找到 ApiCredentials

    在区分大小写的环境中说“Set-Cookie”可能更安全。

    【讨论】:

      猜你喜欢
      • 2014-03-03
      • 2013-06-12
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多