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