Google App Engine 上的 python 请求不适用于 HTTPS [英] python requests on Google App Engine not working for HTTPS

查看:24
本文介绍了Google App Engine 上的 python 请求不适用于 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Google App Engine 上使用 python-request,但它在 HTTPS 上没有按预期工作.让我们看一个例子:

I'm using python-request on Google App Engine and it's not working as expected for HTTPS. Let's see an example:

import requests
requests.get('https://www.digitalocean.com')

如果我在终端中执行它,那条线就可以完美运行.响应为 200 OK(无重定向).

That line works perfectly if I execute it in a terminal. Response is 200 OK (without redirects).

但是,如果我在 GAE 上执行它,则会引发 TooManyRedirects 错误.试图找出我使用 allow_redirects=False 执行的问题是什么,我可以看到响应是重定向(301),它指向相同的 url !!!(位置"标头值为https://www.digitalocean.com").这显然(当 allow_redirect=True 时)一遍又一遍地发生,直到引发 TooManyRedirects 错误为止.

However, if I execute it on GAE a TooManyRedirects error is raised. Trying to figure out what's the problem I execute with allow_redirects=False and I can see that the response is a redirect (301) which points to the same url!!! ('location' header value is 'https://www.digitalocean.com'). This obviously (when allow_redirect=True) happens over and over again until the TooManyRedirects error is raised.

因此,python-requests 似乎不适用于 HTTPS 的 GAE(我已经使用多个 URL 进行了测试).然而,HTTP 工作得很好.

So it seems that python-requests is not working on GAE for HTTPS (I've tested with several URL). However HTTP works perfectly.

知道发生了什么吗?

提前致谢.

推荐答案

降级到 requests==2.1.0 对我有用.

Downgrading to requests==2.1.0 worked for me.

拥有最新的 urllib3 对于解决不相关的错误很重要(我记得是import pwd).

Having an up-to-date urllib3 is important for resolving an unrelated bug (import pwd, as I recall).

希望 App Engine 尽快修复此问题,因为请求不会.

Hopefully App Engine fixes this soon, as requests won't.

我认为您也可以通过评论行在最新请求中修补此问题session.py 中的 161-175.未经测试.

I think you can also patch this in the latest requests by commenting lines 161-175 in sessions.py. Untested.

这篇关于Google App Engine 上的 python 请求不适用于 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆