小编Dat*_*ery的帖子

FastAPI - GET 请求导致类型错误(值不是有效的字典)

这是我的数据库架构。

\n

在此输入图像描述

\n

我这样定义我的架构:

\n

从 pydantic 导入 BaseModel

\n
class Userattribute(BaseModel):\n    name: str\n    value: str\n    user_id: str\n    id: str\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的模型:

\n
class Userattribute(Base):\n    __tablename__ = "user_attribute"\n\n    name = Column(String)\n    value = Column(String)\n    user_id = Column(String)\n    id = Column(String, primary_key=True, index=True)\n
Run Code Online (Sandbox Code Playgroud)\n

在 crud.py 中我定义了一个get_attributes方法。

\n
def get_attributes(db: Session, skip: int = 0, limit: int = 100):\n    return db.query(models.Userattribute).offset(skip).limit(limit).all()\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的GET终点:

\n
@app.get("/attributes/", response_model=List[schemas.Userattribute])\ndef read_attributes(skip: int = 0, limit: int = 100, db: Session = …
Run Code Online (Sandbox Code Playgroud)

python get pydantic fastapi

32
推荐指数
1
解决办法
5万
查看次数

ValueError:超出整数字符串转换的限制(4300)

>>> import sys
>>> sys.set_int_max_str_digits(4300)  # Illustrative, this is the default.
>>> _ = int('2' * 5432)
Traceback (most recent call last):
...
ValueError: Exceeds the limit (4300) for integer string conversion: value has 5432 digits.
Run Code Online (Sandbox Code Playgroud)

Python 3.10.7 引入了类型转换的这一重大更改。

文档:整数字符串转换长度限制

其实我不明白为什么

  1. 这是介绍和
  2. 默认值4300从何而来?听起来像是任意数字。

python python-3.x python-3.10

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

VueJS 和 Firebase - 导入 firebase 包的正确方法

我很难正确导入 firebase SDK。我使用 Vue3 并通过安装 firebaseyarn add firebase

这是我的 firebase.js 文件:

import firebase from 'firebase/app';
Run Code Online (Sandbox Code Playgroud)

但是,这会导致以下错误:1:1 error 'firebase/app' should be listed in the project's dependencies. Run 'npm i -S firebase/app' to add it import/no-extraneous-dependencies

import firebase from 'firebase';
Run Code Online (Sandbox Code Playgroud)

这有效,但我收到以下警告:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the module builds, these are …
Run Code Online (Sandbox Code Playgroud)

firebase vue.js

6
推荐指数
1
解决办法
2081
查看次数

循环中元素的VueJS转换?

这是我的代码:我想在每次数据更新时在 HelloWorld 组件上创建一个转换。过渡本身工作正常

  <transition name="fade">
    <p v-if="awesome">Vue is awesome</p>
  </transition>
Run Code Online (Sandbox Code Playgroud)

这是我动态创建的“卡片”。

  <v-row no-gutters>
    <v-col cols="12" sm="4" md="4" v-for="(todo, index) in todos" v-bind:key="index">
      <v-card class="pa-2" outlined tile>
        <transition name="fade">
          <HelloWorld
            v-bind:todos="todos"
            v-bind:index="index"
            v-bind:class="(todos[index].done)?'green':'red'"
          />
        </transition>
      </v-card>
    </v-col>
  </v-row>
Run Code Online (Sandbox Code Playgroud)

此处过渡不起作用。

CSS在这里:

<style scoped>
.top {
  background: blue;
  color: white;
  display: flex;
  justify-content: space-around;
  border-bottom: 2.5px solid black;
}

.fade-enter {
  opacity: 0;
}

.fade-enter-active {
  transition: opacity 1s;
}

.fade-leave {
}

.fade-leave-active {
  transition: 1s;
  opacity: 0;
}
</style>
Run Code Online (Sandbox Code Playgroud)

为什么以及如何让它工作?

transition vue.js

5
推荐指数
1
解决办法
3014
查看次数

Docker Swarm 错误 - 类型的安装配置无效

这是我的 Docker compose/stack 文件。当我在单个节点上部署时,一切正常,但当我在多个节点上部署时,出现以下错误:

绑定类型的挂载配置无效 绑定源路径不存在

version: '3'
services:
  shinyproxy:
    build: /etc/shinyproxy
    deploy: 
      replicas: 3
    user: root:root
    hostname: shinyproxy
    image: shinyproxy-example
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 5000:5000
    networks: 
      - proxynetwork
  mysql:
    image: mysql
    deploy: 
      replicas: 3    
    volumes:
      - /mysqldata:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: keycloak
      MYSQL_USER: keycloak
      MYSQL_PASSWORD: password
    networks: 
      - proxynetwork
  keycloak:
    deploy: 
      replicas: 3  
    image: jboss/keycloak
    volumes:
      - /etc/letsencrypt/live/ds-gym.de/fullchain.pem:/etc/x509/https/tls.crt
      - /etc/letsencrypt/live/ds-gym.de/privkey.pem:/etc/x509/https/tls.key
      #- /theme/govuk-social-providers/:/opt/jboss/keycloak/themes/govuk-social-providers/
    environment:
      - PROXY_ADDRESS_FORWARDING=true
      - KEYCLOAK_USER=myadmin
      - KEYCLOAK_PASSWORD=mypassword
    ports:
      - 8443:8443
    networks: 
      - proxynetwork

networks: …
Run Code Online (Sandbox Code Playgroud)

docker-compose docker-swarm docker-stack

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

将具有多个数组的对象转换为对象数组

我对从 API 获得的数据进行了大量处理:

这是数据返回的方式,数组的数量不同。

const objData = {
    arr1: [1,2,3],
    arr2: [1,2,1],
    arr3: [2,1,2],
    arr4: ["a","b", "c"]
}
Run Code Online (Sandbox Code Playgroud)

这是它应该看起来的样子

const desired = [
    {a: 1, b: 1, c: 2, d: "a"},
    {a: 2, b: 2, c: 1, d: "b"},
    {a: 2, b: 1, c: 2, d: "c"}
]
Run Code Online (Sandbox Code Playgroud)

这给了我想要的结果,但它不是动态的,因为我必须提供数组的名称,并且不允许更改对象中的数组数量。

const DataObj = []

for (let i = 0; i < objData.arr1.length; i++) {
    const objX = {
        a: objData.arr1[i],
        b: objData.arr2[i],
        c: objData.arr3[i],
        d: objData.arr4[i],
    }
    DataObj.push(objX)
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个问题吗?如何使其独立于数组的名称和数据集中的数组数量?

javascript arrays object

5
推荐指数
1
解决办法
174
查看次数

使用Python连接redis Sentinel导致MasterNotFound错误

我对 Docker-Compose 有以下设置:

version: '2'

services:
  redis-sentinel:
    image: docker.io/bitnami/redis-sentinel:6.2
    volumes:
      - redis-sentinel_data:/bitnami
  redis:
    image: docker.io/bitnami/redis:6.2
    environment:
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - redis_data:/bitnami
volumes:
  redis-sentinel_data:
    driver: local
  redis_data:
    driver: local
Run Code Online (Sandbox Code Playgroud)

我的主人的名字应该是mymaster

(base)>docker exec redis_redis-sentinel_1 redis-cli -p 26379 sentinel get-master-addr-by-name mymaster
192.168.80.3
6379
Run Code Online (Sandbox Code Playgroud)

我尝试通过 Python 连接:

from redis.sentinel import Sentinel

sentinel = Sentinel([("localhost", 26379)], socket_timeout=0.5)
r = sentinel.master_for("mymaster")
Run Code Online (Sandbox Code Playgroud)

这会导致以下错误。

redis.sentinel.MasterNotFoundError: No master found for 'mymaster'
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

  • 将 localhost 更改为我的 docker 主机 IP 地址
  • 检查 …

python redis redis-sentinel

5
推荐指数
0
解决办法
1100
查看次数

Shell 脚本:使用自己的 IP 地址作为变量

我必须编写一个 shell 脚本来初始化 docker swarm。

我需要将自己的 IP 地址作为参数传递:

 sudo docker swarm init --advertise-addr 167.172.176.134
Run Code Online (Sandbox Code Playgroud)

我怎样才能动态地做到这一点?我知道该ifconfig命令,它允许我查看 IP,但我无法将整个内容作为变量传递。它应该是这样的

ip = ifconfig["IP"]
sudo docker swarm init --advertise-addr $ip
Run Code Online (Sandbox Code Playgroud)

linux bash shell

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

Python 列表理解:如果列表仅包含一个元素,则取消列表

我有以下功能:

output_names = [output.name for output in session.get_outputs()]
Run Code Online (Sandbox Code Playgroud)

session.get_outputs()可以返回我想从中获取名称属性的多个对象。如果列表的长度为1,我希望output_names是一个值,而不是一个只有单个值的列表。

output_names = [output.name for output in session.get_outputs()]
if len(output_names) == 1:
    output_names = output_names[0]
Run Code Online (Sandbox Code Playgroud)

我可以这样做,但这感觉像是代码味道。有没有更优雅的方法来解决这个问题?

python list-comprehension list

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

使用 docker 在不同端口上运行 Vue.js 应用程序

我使用非常基本的配置创建了一个简单的 VueJS 应用程序。我使用 webpack 配置来做到这一点。

\n\n
vue init webpack app\n
Run Code Online (Sandbox Code Playgroud)\n\n

我构建这个简单的Dockerfile

\n\n
FROM node:lts-alpine\n\n# install simple http server for serving static content\nRUN npm install -g http-server\n\n# make the \'app\' folder the current working directory\nWORKDIR /app\n\n# copy both \'package.json\' and \'package-lock.json\' (if available)\nCOPY package*.json ./\n\n# install project dependencies\nRUN npm install\n\n# copy project files and folders to the current working directory (i.e. \'app\' folder)\nCOPY . .\n\n# build app for production with minification\nRUN npm run build\n\nEXPOSE 3838\nCMD [ "http-server", "dist" ]\n …
Run Code Online (Sandbox Code Playgroud)

deployment docker vue.js

0
推荐指数
1
解决办法
2226
查看次数

Method chaining in python results in an error

I thought in Python I am allowed to perform method chaining.

basket = [1,3,2,4,6,8]

basket.append(7)
basket.sort()
basket.reverse()
Run Code Online (Sandbox Code Playgroud)

This works.

basket.append(7).sort().reverse()
Run Code Online (Sandbox Code Playgroud)

This does not.

AttributeError: 'NoneType' object has no attribute 'sort'
Run Code Online (Sandbox Code Playgroud)

I am not sure what is going on here, but I assume that happens because in place methods result in "NoneType" result = basket.sort() and therefore the second method will be performed on the result and not the original object.

Can anyone help me how to do these operations without …

python methods list

-1
推荐指数
1
解决办法
40
查看次数