小编VVK*_*mar的帖子

psycopg2.OperationalError:无法连接到服务器:连接被拒绝服务器是否在主机“localhost”上运行

执行 docker-compose up 时出错。

conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml:-

version: '3'

services:
  dcs_web:
    build: .
    depends_on:
      - db
    ports:
      - "5000:5000"
  db:
    image: postgres:latest
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - "5433:5433"
    environment:
      - …
Run Code Online (Sandbox Code Playgroud)

python psycopg2 flask docker docker-compose

4
推荐指数
1
解决办法
2万
查看次数

如何在烧瓶中使用 request.args.get() ?

如果 url 查询字符串拼写错误,如何抛出异常?

解释 :

这是获取特定用户的 url: http://127.0.0.1:5000/v1/t/user/?user_id=1。如果持续下去,http://127.0.0.1:5000/v1/t/user/它将给出用户列表。

问题:

如果user_id查询字符串中的拼写错误(例如错误)怎么办use_id=1,或者不是传递整数值,而是传递字符串值,user_id我希望在这种情况下我应该返回 404 页面。我不认为内部request.args.get()会抛出?如果我必须处理这种情况该怎么办?

我的代码的一部分:

page_index = request.args.get('index', 1, type=int)
max_item = request.args.get('max', 1, type=int)
userID = request.args.get('user_id', type=int)
Run Code Online (Sandbox Code Playgroud)

python flask python-3.x

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

flask ×2

python ×2

docker ×1

docker-compose ×1

psycopg2 ×1

python-3.x ×1