1

I have the code below which is built on top of ndb.

When running I receive the two errors below.

Can I ask for some guidance, specifically what is the connection_from_host referring to?

import flask
import config
import util
app = flask.Flask(__name__)
from google.appengine.api import app_identity
from google.appengine.api import taskqueue, search, memcache
from apiclient.discovery import build, HttpError
from google.cloud import ndb
#from oauth2client.client import GoogleCredentials
from apiclient.http import MediaIoBaseUpload
from datetime import datetime, timedelta
from functools import partial
from io import BytesIO
import os
from os.path import splitext, basename
from model import Config
from model import VideosToCollections
from pytz import timezone
import datetime
import httplib2
import iso8601
import time
import requests
import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch()
from operator import attrgetter
import model
from model import CallBack
import re
import config
import google.appengine.api
client = ndb.Client()
def ndb_wsgi_middleware(wsgi_app):
 def middleware(environ, start_response):
 with client.context():
 return wsgi_app(environ, start_response)
 return middleware
app.wsgi_app = ndb_wsgi_middleware(google.appengine.api.wrap_wsgi_app(app.wsgi_app))
@app.route('/collectionsync/', methods=['GET'])
#@ndb.transactional
def collectionsync():
 collection_dbs, collection_cursor = model.Collection.get_dbs( order='name' )

This returns:

/layers/google.python.pip/pip/lib/python3.12/site-packages/urllib3/contrib/appengine.py:111: 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/1.26.x/reference/urllib3.contrib.html.

google.api_core.exceptions.RetryError: Maximum number of 3 retries exceeded while calling <function make_call..rpc_call at 0x3ee3d42d6840>, last exception: 503 Getting metadata from plugin failed with error: '_AppEnginePoolManager' object has no attribute 'connection_from_host'

Basheer Jarrah
6894 silver badges17 bronze badges
asked May 15 at 3:55
6
  • Change app.wsgi_app = ndb_wsgi_middleware(google.appengine.api.wrap_wsgi_app(app.wsgi_app)) to app.wsgi_app = ndb_wsgi_middleware(app.wsgi_app) Commented May 15 at 14:55
  • Thank you, I redeployed and triggered scheduled event. Same error Commented May 15 at 15:15
  • 2025年05月15日 15:14:04 sync[20250515t110814] /layers/google.python.pip/pip/lib/python3.12/site-packages/urllib3/contrib/appengine.py:111: AppEnginePlatformWarning: urllib3 is using URLFetch on Google App Engine sandbox instead of sockets. To use sockets directly instead of URLFetch see urllib3.readthedocs.io/en/1.26.x/reference/urllib3.contrib.html. Commented May 15 at 15:17
  • 2025年05月15日 15:14:11 sync[20250515t110814] File "/workspace/util.py", line 196, in get_dbs 2025年05月15日 15:14:11 sync[20250515t110814] model_dbs, next_cursor, more = query.fetch_page( 2025年05月15日 15:14:11 sync[20250515t110814] ^^^^^^^^^^^^^^^^^ Commented May 15 at 15:18
  • 323, in _advance_tasklet 2025年05月15日 15:14:11 sync[20250515t110814] yielded = self.generator.send(send_value) 2025年05月15日 15:14:11 sync[20250515t110814] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Commented May 15 at 15:18

1 Answer 1

1

I think the presence of requests_toolbelt dependency in your project caused the issue. It may have forced the requests library to use Google App Engine’s URLFetch service (urllib3), which requires URLFetch to be present. I think that was often necessary in the Python 2 runtime environment on GAE, but not in Python 3.

You may try removing requests_toolbelt from your requirements.txt file (see this post).

There’s also a possibility that the URLFetch warning is somewhat related to the RetryError connection_from_host. You should try migrating URLFetch to standard Python libraries compatible with the Python 3 GAE environment. Refer to this documentation for steps on replacing the URL Fetch API with a Python library, and you may also consider bypassing URLFetch.

I hope this helps.

answered May 16 at 8:58
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! requests_toolbelt was polluting the scope! I'm testing the sync service now. Out of curiousity, does ndb use tcp to talk to the google datastore cluster?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.