Matheus Theu
Matheus Theu

Reputation: 11

Error when trying to register entity in datastore (app engine) localhost

I'm getting this error in response to my attempt to put an entity

this also occurs in queries, as if my application was not connected to the datastore emulator

error: Maximum number of 3 retries exceeded while calling <function make_call..rpc_call at 0x7fba88531510>, last exception: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:8000: Trying to connect an http1.x server

I'm running my application with python3 main.py

calling an endpoint from my app that creates a simple entity in the datastore the error occurs.

save my entity and create a kind of it locally.

main.py

import uvicorn
from fastapi import FastAPI
from google.cloud import ndb

app = FastAPI()
ds_client = ndb.Client()

class Neighborhood(ndb.Model):
    db_id = ndb.ComputedProperty(lambda self: self.key.id())
    name = ndb.StringProperty(required=True)
    zone = ndb.StringProperty()
    active = ndb.BooleanProperty(default=True)

@app.get("/test2")
def fetch_neighborhood():
    'get most recent Neighborhood'
    with ds_client.context():
        return Neighborhood.query().fetch()

@app.post("/test")
def store_neighborhood():
    'create new Neighborhood entity in Datastore'
    with ds_client.context():
        namespace = 'client2'
        neighborhood = Neighborhood(id=123, namespace=namespace)
        neighborhood.name = "test"
        neighborhood.put()
    
if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=True)

bash

#!/bin/bash

HOST=localhost
PY_PATH=python27=/usr/bin/python2.7,python3=/usr/bin/python3

export APPLICATION_ID=dev~None
export GOOGLE_APPLICATION_CREDENTIALS="./app_engine_service_account_dev.json"
export DEPLOY_ENVIRONMENT=development
export HTTP_HOST="localhost:8080"

python3 ~/google-cloud-sdk/bin/dev_appserver.py \
    --port=8080 \
    --host=$HOST \
    --support_datastore_emulator=true \
    --runtime_python_path=$PY_PATH \
app-dev.yaml
# --clear_datastore=yes \

yaml

runtime: python310
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app
instance_class: F1
automatic_scaling:
  target_cpu_utilization: 0.7
  min_instances: 1
  max_instances: 1
  min_pending_latency: 30ms  # default value
  max_pending_latency: automatic
  max_concurrent_requests: 32
  max_idle_instances: 0

skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^(.*/)?.*\.bak$
- ^(.*/)?.*deploy.sh$
- ^(.*/)?docs/*$
- ^(.*/)?venv/*$
- ^(.*/)?downloads/*$

env_variables:
  DEPLOY_ENVIRONMENT: 'development'

  DATASTORE_EMULATOR_HOST: 'localhost:8000'
  DATASTORE_EMULATOR_HOST_PATH: 'localhost:8000/datastore'
  DATASTORE_HOST: 'http://localhost:8000'
  HTTP_HOST: 'localhost:8080'

  STORAGE_EMULATOR_HOST: 'http://localhost:9023'

Upvotes: 1

Views: 86

Answers (0)

Related Questions