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

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

问题描述

我在Google App Engine上使用python-request,并且HTTPS无法按预期工作。我们来看一个例子:

pre $ 导入请求
requests.get('https://www.digitalocean.com' )

如果我在终端中执行它,这条线就完美了。响应是200 OK(没有重定向)。

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



所以python-requests似乎不适用于HTTPS的GAE我已经测试了几个URL)。然而,HTTP完美地工作。



有什么想法发生了什么?



预先感谢。

解决方案

降级到请求== 2.1.0为我工作。

拥有最新的urllib3对于解决一个不相关的bug( import pwd ,如我记得的)。



希望App Engine很快就能解决这个问题,因为要求不会的。



编辑:



我认为你也可以在最新的要求中修改这个,通过评论 sessions.py中的第161-175行。未经测试。


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')

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

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.

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

Any idea about what's happening?

Thanks in advance.

解决方案

Downgrading to requests==2.1.0 worked for me.

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

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

EDIT:

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天全站免登陆