나는 예상대로 티피 링크의 URL (스마트 플러그 켭니다)와 인터페이스하는 의미와 작동합니다 다음 curl 명령이 있습니다호환성
이curl --request POST "https://wap.tplinkcloud.com/?token=[token] HTTP/1.1" \
--data '{"method":"passthrough", "params": {"deviceId": "[deviceid]", "requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}" }}' \
--header "Content-Type: application/json"
이
이 예는 위의 예상 수행 등을 내 내비게이션 스마트 플러그가 켜집니다. 파이썬 요청에 번역하려고 할 때, 나는 이것을 사용하고 있습니다 :
url = "https://wap.tplinkcloud.com?token=[token] HTTP/1.1"
data = "{\"method\":\"passthrough\", \"params\": {\"deviceId\": \"[deviceid]\", \"requestData\": \"{\\\"system\\\":{\\\"set_relay_state\\\":{\\\"state\\\":1}}}\" }}"
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
r = requests.post(url, data=data, headers=headers)
print r.text
내 출력은 다음과 같습니다
{"error_code":-20651,"msg":"Token expired"}
두 요청이 동일한 토큰 및 장치 ID를 사용하고 있습니다.
나는 둘 요청에 httpbin.org을 사용하고, 이것은 내가보고하고 비교입니다 :
말림 :
{
"args": {},
"data": "{\"method\":\"passthrough\", \"params\": {\"deviceId\": \"[deviceid]\", \"requestData\": \"{\\\"system\\\":{\\\"set_relay_state\\\":{\\\"state\\\":1}}}\" }}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Connection": "close",
"Content-Length": "160",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.54.0"
},
"json": {
"method": "passthrough",
"params": {
"deviceId": "[deviceid]",
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}"
}
},
"origin": "[myip]",
"url": "http://httpbin.org/post"
}
파이썬 : 뭔가 분명 내가
{
"args": {},
"data": "{\"method\":\"passthrough\", \"params\": {\"deviceId\": \"[deviceid]\", \"requestData\": \"{\\\"system\\\":{\\\"set_relay_state\\\":{\\\"state\\\":1}}}\" }}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Charset": "UTF-8",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "160",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": {
"method": "passthrough",
"params": {
"deviceId": "[deviceid]",
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}"
}
},
"origin": "[myip]",
"url": "http://httpbin.org/post"
}
있는가 내가 잘못 했니? 헤더 문제가있을 수 있습니까?
는 "https://wap.tplinkcloud.com?token=[token] HTTP/1.1"그냥 곱슬 곱슬 예에서 일을하기 때문에 것을 사용 사실의 URL – Tomalak
아니다. 그러나 그것을 제거하는 것은 아무런 효과가 없습니다. – Ryan
글쎄, "Token expired"메시지는 꽤 명확합니다. 페이로드에 문제가 있다고 생각하지 않습니다. – Tomalak