AppEnginePlatformWarning: urllib3 is using URLFetc

2019-05-07 23:38发布

I'm getting this error on app engine using flask to make a Slack bot. It happens whenever I send a POST request from Slackbot.

Unfortunately, the url provided in the error is a dead link. How do I go about using sockets instead of URLFetch?

/base/data/home/apps/[REDACTED]/lib/requests/packages/urllib3/contrib/appengine.py:115: AppEnginePlatformWarning: urllib3 is using URLFetch on Google App Engine sandbox instead of sockets. To use sockets directly instead of URLFetch see https://urllib3.readthedocs.io/en/latest/contrib.html.

3条回答
一夜七次
2楼-- · 2019-05-07 23:48

You can use the following to silence this:

import warnings
import urllib3.contrib.appengine

warnings.filterwarnings('ignore', r'urllib3 is using URLFetch', urllib3.contrib.appengine.AppEnginePlatformWarning)
查看更多
Deceive 欺骗
3楼-- · 2019-05-07 23:49

For me, turns out the presence of requests_toolbelt dependency in my project was the problem: it somehow forced the requests library to use urllib3, which requires URLFetch to be present, otherwise it raises an AppEnginePlatformError. As suggested in the app engine docs, monkey-patching Requests with requests_toolbelt forces the former to use URLFetch, which is no longer supported by GAE in a Python 3 runtime.

The solution was to remove requests_toolbelt from my requirements.txt file

查看更多
甜甜的少女心
4楼-- · 2019-05-08 00:03

As detailed on Google's Sockets documentation, sockets can be used by setting the GAE_USE_SOCKETS_HTTPLIB environment variable. This feature seems to be available only on paid apps, and impacts billing.

Though the error you posted gets logged as an Error in App Engine, this thread suggests (see reply #8) that the error is actually meant as a warning, which the text "AppEnginePlatformWarning" seems to suggest anyway.

The comment block on the source page for appengine.py is also instructive.

You didn't post any information about your implementation, but on Google App Engine Standard edition, using URLFetch via the AppEngineManager should be just fine, though you will get the error.

查看更多
登录 后发表回答