AppEnginePlatformWarning - 使用套接字的理由? [英] AppEnginePlatformWarning - reason to use sockets?

查看:105
本文介绍了AppEnginePlatformWarning - 使用套接字的理由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google App Engine标准环境中,如果您使用urllib发出HTTPS请求,则会得到一个 AppEnginePlatformWarning ,表示您使用的是urlfetch而不是套接字。



我发现警告很烦人,所以我禁用了它。

  #使用App Engine请求适配器。这可以确保请求使用
#URLFetch。
requests_toolbelt.adapters.appengine.monkeypatch()

#squelch警告
requests.packages.urllib3.disable_warnings(
requests.packages.urllib3.contrib.appengine。 AppEnginePlatformWarning

我的问题是 - 是否有充足的理由切换到套接字?特别是使用urlfetch有什么问题?

解决方案

使用 urlfetch 发出HTTP(S)请求(强调<$


App Engine使用网址抓取服务来发出呼出HTTP(S)
请求。



有关如何实现网址提取服务以及在网址提取请求中发送哪些
标头的详细信息,请参阅出站请求



发出HTTP请求



要发出出站HTTP请求,请使用 urlfetch.fetch
方法。为了改进代码的可移植性,您还可以使用Python
标准库 urllib urllib2 httplib 发出HTTP
请求。当您在App Engine中使用这些库时,它们使用App Engine的URL提取服务执行
HTTP请求。 只要您将它配置为使用
URLFetch,您也可以使用
第三方请求库。


套接字支持在GAE中颇具问题,它具有相当长的限制和限制列表,请参阅套接字Python API概述,特别是限制和限制部分。 警告您看到的不是来自GAE,而是来自您使用的第三方请求库,这就是为什么我在上面的引用中突出显示注释的原因。恕我直言,在GAE上下文中简单地忽略/掩盖警告是安全的。


In the Google App Engine standard environment, if you use urllib to make HTTPS requests, you'll get an AppEnginePlatformWarning which says you're using urlfetch instead of sockets.

I found the warning annoying, so I disabled it.

# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt.adapters.appengine.monkeypatch()

# squelch warning
requests.packages.urllib3.disable_warnings(
    requests.packages.urllib3.contrib.appengine.AppEnginePlatformWarning
)

My question is - is there a good reason to switch to sockets? Specifically what is wrong with using urlfetch?

解决方案

There's nothing wrong with using urlfetch, in fact it is the recommended method for issuing outbound HTTP(S) requests on GAE. From Issuing HTTP(S) Requests (emphasis on requests-related note mine):

App Engine uses the URL Fetch service to issue outbound HTTP(S) requests.

For details about how the URL Fetch service is implemented and which headers are sent in a URL Fetch request, see Outbound Requests.

Issuing an HTTP request

To issue an outbound HTTP request, use the urlfetch.fetch method. For improved code portability, you can also use the Python standard libraries urllib, urllib2, or httplib to issue HTTP requests. When you use these libraries in App Engine, they perform HTTP requests using App Engine's URL Fetch service. You can also use the third-party requests library as long as you configure it to use URLFetch.

The sockets support is rather the problematic one in GAE, it comes with a fairly long list of limitations and restrictions, see Sockets Python API Overview, in particular the Limitations and restrictions section.

The warning you see is not from GAE, it's from the 3rd-party requests library you use, which is why I highlighted the note in the above quote. IMHO it's safe to simply ignore/mask the warning in a GAE context.

这篇关于AppEnginePlatformWarning - 使用套接字的理由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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