osnsyc / GrocyCompanionCN

条形码商品识别
105 stars 11 forks source link

在配置好GrocyCompanionCN后,用curl命令验证时报错。 #2

Closed wuzimuws closed 10 months ago

wuzimuws commented 11 months ago

大佬您好,我在按照教程安装好GrocyCompanionCN后,访问http://192.168.1.115:9288/显示了GrocyCNCompanion Started!。 但是在使用curl -X POST -H "Content-Type: application/json" -d '{"client":"temporary_storage","aimid":"]E0","barcode":"8935024140147"}' http://192.168.1.115:9288/add来验证时,却无法实现数据添加,研究了很久都没有什么思路,还请大佬指点!

具体报错如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

对应的docker日志见下图: CleanShot2023-12-11at21 03 43@2x

我在群晖构建的docker,其中 config.ini为:

# config.ini
[Grocy]
GROCY_URL = http://192.168.1.115
GROCY_PORT = 9283
GROCY_API = zAf***************tRSx
# 默认的数量单位ID
GROCY_DEFAULT_QUANTITY_UNIT_ID = 1
# 默认的保质期天数
GROCY_DEFAULT_BEST_BEFORE_DAYS = 365  
# 存储位置ID,与scanner.ino内的位置名称对应
# shell内获取,替换以下地址\端口\api_key:
; curl -X 'GET' 'https://EXAMPLE.COM:PORT/api/objects/locations' \
; -H 'accept: application/json' \
; -H 'GROCY-API-KEY:YOUR_GROCY_API_KEY' \
; | echo -e "$(cat)"" 
[GrocyLocation]
pantry = 3
temporary_storage = 7
fridge = 2
living_room = 4
bedroom = 6
bathroom = 5
# 注册RapidAPI账号,并在https://rapidapi.com/Glavier/api/barcodes1/的Pricing点击订阅(免费),复制Endpoints中的X_RapidAPI_Key于此处
[RapidAPI]
X_RapidAPI_Key = 6d***************cd

注:可以用curl命令获取到[GrocyLocation]

docker-compose.yml配置如下:

# docker-compose.yml
version: "3"
services:
  spider:
    image: osnsyc/grocycompanioncn:latest
    restart: no
    ports:
      - "9288:9288"
    volumes:
      - /volume1/docker/GrocyCompanionCN/config/config.ini:/usr/src/app/config.ini
      # - ./u2net.onnx:/root/.u2net/u2net.onnx
    networks:
      - grocy_cn_campanion

networks:
  grocy_cn_campanion:
osnsyc commented 11 months ago

none is not an allowed value (type=type_error.none.not_allowed) default_quantity_unit_purchase none is not an allowed value (type=type_error.none.not_allowed) quantity_unit_stock

应该是grocy“数量单位”没有配置。

  1. grocy中,数量单位-添加
  2. 查询数量ID. curl -X 'GET' 'https://EXAMPLE.COM:PORT/api/objects/quantity_units' \ -H 'accept: application/json' \ -H 'GROCY-API-KEY:YOUR_GROCY_API_KEY' \ | echo -e "$(cat)"
  3. 修改ID值 # config.ini GROCY_DEFAULT_QUANTITY_UNIT_ID = 1
  4. 重启. docker compose down, docker compose up -d

另,即使日志报错,不完整的条目仍有可能强制添加至grocy,请先在管理主数据-产品中清理

wuzimuws commented 11 months ago

感谢大佬,跑通了~ 我查询出的数量ID是从2开始的,感谢!