简体   繁体   English

401未经JSON授权

[英]401 Unauthorized with JSON

I got an error when i run the bash script below. 运行以下bash脚本时出现错误。

pi@raspberrypi:~/dev-domoticz/scripts $ ./dht_22.sh
21.2
48.2
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: SID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT
<html><head><title>Unauthorized</title></head><body><h1>

This script reads the DHT22 chip for temp and humidity dht_22.sh and communicate with the Domoticz server with json. 该脚本读取DHT22芯片的温度和湿度dht_22.sh,并使用json与Domoticz服务器通信。 So i can see the current temp/humi on my Domoticz server: 这样我就可以在Domoticz服务器上看到当前的温度/湿度:

#!/bin/sh
# Domoticz server
SERVER="10.0.0.110:8080"
# DHT IDX
DHTIDX="4"

# DHTPIN
DHTPIN="4"

# TEMP FILE
TMPFILE="/var/tmp/temp.txt"

cpt=0
while [ $cpt -lt 6 ]
do
TEMP=""

sleep 5

sudo nice -20 /home/pi/dev-domoticz/scripts/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 $DHTPIN > /var/tmp/temp.t$
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp" | awk '{ print $3 }')
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp")

TEMP=$(awk ' /Temp/ {print substr ($0,6,4)}' /var/tmp/temp.txt)
HUM=$(awk ' /Humidity/ {print substr ($0,22,4)}' /var/tmp/temp.txt)
echo $TEMP
echo $HUM

# Send data
curl  -s -i -H "Accept: application/json" "http://10.0.0.110:8080/json.htm?type=command&param=udevice&idx=$DHTIDX&nv$

TEMP=""
HUM=""

exit 0
cpt=$(($cpt+1))
done
exit 1

When i just run the json line in a browser, i also receive a 401 Unauthorized error. 当我仅在浏览器中运行json行时,我还会收到401未经授权的错误。 I gues i have to enter some login information, so i also tryed something like this: 我猜我必须输入一些登录信息,所以我也尝试了以下方法:

http://10.0.0.110:8080/json.htm?username=test=&password=test=&type=command&param=udevice&idx=4&nvalue=0&svalue=21;40;2

But still the 401 error. 但是仍然是401错误。

Can some one help me out? 有人可以帮我吗?

Well, cost me some time but it work now. 好吧,花了我一些时间,但是现在可以了。 Your solution was correct Viktor Khilin but my Domoticz software gave me some problems. 您的解决方案是正确的Viktor Khilin,但是我的Domoticz软件给我带来了一些问题。

The solution was this: 解决方案是这样的:

curl -s -i -H "Accept: application/json" "http://10.0.0.110:8080/json.htm?&username=test=&password=test=&type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"

Thanks for helping me out. 谢谢你的协助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用GuzzleHttp \\ Client发布JSON:返回401未经授权的错误 - POSTing JSON with GuzzleHttp\Client: returning 401 Unauthorized error httpResponse 401未经授权 - httpResponse 401 unauthorized 在C#中使用Rest JSON API时获得401未经授权的Web异常 - Get 401 unauthorized web exception when consuming rest json api in c# Spring MVC(或Spring Boot)。 针对安全相关异常的自定义JSON响应,如401 Unauthorized或403 Forbidden) - Spring MVC (or Spring Boot). Custom JSON response for security related exceptions like 401 Unauthorized or 403 Forbidden) 当 Java 出现 401 Unauthorized 错误时,如何捕获 POST 请求的 json 响应? - How do I capture the json response of a POST request when the 401 Unauthorized error occurs with Java? AFNetworking回复问题:未经授权(401) - AFNetworking issue with response : unauthorized (401) 如何调试401未经授权的错误? - How debug 401 unauthorized error? JWT 401:在 Slim 3 框架中未经授权 - JWT 401: Unauthorized in Slim 3 framework 使用无头 WP CMS 后端从 Angular2+ 获取 https://.../wp-json/wp/v2/users/me 401(未经授权) - GET https://…/wp-json/wp/v2/users/me 401 (Unauthorized) from Angular2+ with Headless WP CMS backend onelogin api与php curl 401未经授权 - onelogin api with php curl 401 unauthorized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM