我正在尝试将 GCP 的 postgresql 数据库连接到 Flask 应用程序,我一直在遵循 GCP 指南:
https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres
但问题是当我尝试在本地运行服务器时,它一直说:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/cloudsql/omedyari:us-west2:kong/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)
我很困惑,我尝试在互联网上搜索并浏览了很多 GCP 文档,但我真的不知道为什么这不起作用。
我就是这样设置 URI 的:
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://[USERNAME]:[PASSWORD]@/postgres?host=/cloudsql/[CONNECTION_NAME]/[DB_NAME]'
Run Code Online (Sandbox Code Playgroud) 所以我试图在我的代码中访问 getResources(),但由于某种原因,它不断收到未解析的引用。我正在另一个类中为我的阵列适配器执行此操作。是因为我没有 main 方法还是因为其他原因?总的来说,我对 android dev 和 kotlin 有点陌生,所以任何帮助都将不胜感激。
class ForecastAdapter(val forecast: Forecast) : RecyclerView.Adapter<ForecastData>(){
override fun getItemCount(): Int {
return forecast.list.count()
}
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ForecastData {
val layoutInflator = LayoutInflater.from(p0?.context)
val cellForRow = layoutInflator.inflate(R.layout.weather_row, p0, false)
return ForecastData(cellForRow)
}
override fun onBindViewHolder(p0: ForecastData, p1: Int) {
val drawableId: Int = getResources().getIdentifier("my_drawable", "drawable", getPackageName())
val getWeather = forecast.list[p1]
val clouds = getWeather.weather[0]
val getDateTime = forecast.list[p1]
var getIcon = forecast.list[p1]
var icon = getIcon.weather[0]
p0.view.textView_text_clouds.text = …
Run Code Online (Sandbox Code Playgroud)我正在尝试使用 Flask 制作一个多租户应用程序,我一直在遵循本指南,我正在使用 Postgres sql 作为数据库:
https://medium.com/@smirnov.am/multitenancy-with-flask-6f5375a34f55
所以我的困惑点是,当我尝试重定向到指定的 url 时,我不断收到内部服务器错误,当我查看日志时,这就是我得到的:
TypeError: index() got an unexpected keyword argument 'organization_name'
在遵循指南时,我将执行与他所做的完全相同的步骤,但我无法获得最终输出以表明它确实有效。
这就是我构建 app.route 的方式
@app.route("/<organization_name>/users")
def index(organization__name):
organization_session = get_organization_session(organization__name)
if not organization_session:
print(404)
users = organization_session.query(Organization).all()
return jsonify({organization__name: [i.username for i in users]})
Run Code Online (Sandbox Code Playgroud)
这就是我设置多租户设置的方式:
DB_URI = my postgres uri
# Manages the the multiple dbs for the organization
@simple_cache
def get_known_organizations():
organizations = Organization.query.all()
return [o.name for o in organizations]
def prepare_bind(organization):
if organization not in current_app.config['SQLALCHEMY_BINDS']:
current_app.config['SQLALCHEMY_BINDS'][organization] = DB_URI.format(organization)
return …
Run Code Online (Sandbox Code Playgroud)