4

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.

ttremblay
  • 71
  • 1
  • 5

3 Answers3

7

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.

HondaGuy
  • 1,251
  • 12
  • 29
3

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)
r3m0t
  • 1,850
  • 16
  • 21
  • where can I put this? I am using a library that does this from within. Do I need to edit the library's source? – Divij Sehgal Apr 03 '18 at 18:25
  • 1
    @divij put it near the beginning of your `main()` function or just before you call the library for the first time. It will apply to everything in your program until it exits. – r3m0t Apr 06 '18 at 08:15
  • Okay I will try that! – Divij Sehgal Apr 07 '18 at 17:37
  • 1
    just in case - you can add this to appengine_config.py to ignore the warning `import warnings warnings.filterwarnings('ignore', r'urllib3')` – Dmitry L. Aug 07 '19 at 14:40
1

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

kip2
  • 6,473
  • 4
  • 55
  • 72