Python "Anfragen" funktioniert einwandfrei, gibt jedoch '403' auf eine Anfrage zurück, die Curl '200' zurückgibtPython

Python-Programme
Anonymous
 Python "Anfragen" funktioniert einwandfrei, gibt jedoch '403' auf eine Anfrage zurück, die Curl '200' zurückgibt

Post by Anonymous »

Ich verwende eine Python -Bibliothek namens libtado (https://github.com/germainlefebvre4/liBtado). Es funktioniert gut, aber eine Anfrage antwortet mit 403 , obwohl dieselbe Anforderung 200 erhält, wenn Google Chrome es macht. Ich habe hier auf Stackoverflow und anderen Websites einige Themen darüber gelesen, und ich kann das Problem nicht genau bestimmen.

Code: Select all

from libtado.api import Tado
t = Tado(token_file_path=token_file_path)

print(t.get_schedule_timetables(2))
print("-------------------")
print(t.set_early_start(2, False))
print("-------------------")
t.set_schedule(2, 1)
< /code>
... gibt dieser Ausgabe: < /p>
(venv-libtado) PS C:\Git\tado-schedules> python tado-schedules-and-sheets.py -s 0
[{'id': 0, 'type': 'ONE_DAY'}, {'id': 1, 'type': 'THREE_DAY'}, {'id': 2, 'type': 'SEVEN_DAY'}]
-------------------
{'enabled': False}
-------------------
Traceback (most recent call last):
File "C:\Git\tado-schedules\tado-schedules-and-sheets.py", line 164, in 
t.set_schedule(2, 1)
File "C:\Git\tado-schedules\venv-libtado\Lib\site-packages\libtado\api.py", line 1049, in set_schedule
return self._api_call('homes/%i/zones/%i/schedule/activeTimeTable' % (self.id, zone), payload, method='PUT')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Git\tado-schedules\venv-libtado\Lib\site-packages\libtado\api.py", line 294, in _api_call
res = call_put(url, data)
^^^^^^^^^^^^^^^^^^^
File "C:\Git\tado-schedules\venv-libtado\Lib\site-packages\libtado\api.py", line 275, in call_put
r.raise_for_status()
File "C:\Git\tado-schedules\venv-libtado\Lib\site-packages\requests\models.py", line 1026, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://my.tado.com/api/v2/homes/[myzone]/zones/2/schedule/activeTimeTable
Die ersten HTTP -Aufrufe erhalten also 200 . Einer von ihnen ist GET (https://github.com/germainlefebvre4/liB ... py#l949999), einer wird put (https://github.com/germainlefebvre4/liB ... I.PY#L1473). (Ich habe ein paar andere ausprobiert, sie funktionieren auch.)
, aber set_schedule () (https://github.com/germainlefebvre4/liB ... i.py#l1010) funktioniert jedoch nicht. In der offiziellen Website von Tado erhält die Anfrage 200 . Dies heißt Anfrage von Google Chrome (kopiert für Bash): < /p>

Code: Select all

curl 'https://my.tado.com/api/v2/homes/[myzone]/zones/2/schedule/activeTimetable?ngsw-bypass=true' \
-X 'PUT' \
-H 'accept: application/json, text/plain, */*' \
-H 'accept-language: nl,en-US;q=0.9,en;q=0.8,de;q=0.7' \
-H 'authorization: Bearer [mytoken]' \
-H 'content-type: application/json' \
-H 'origin: https://app.tado.com' \
-H 'priority: u=1, i' \
-H 'referer: https://app.tado.com/' \
-H 'sec-ch-ua: "Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-site' \
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36' \
-H 'x-amzn-trace-id: tado=webapp-release/v3786' \
--data-raw '{"id":1}'
So I replaced (https://github.com/germainlefebvre4/lib ... 3C4-L106C6) with:

Code: Select all

self.access_headers = {
#'Authorization': f'Bearer {access_token}', # Changed to mimic Google Chrome
#'User-Agent': 'python/libtado', # Changed to mimic Google Chrome
# Added to mimic Google Chrome:
"authority": "my.tado.com",
"method": "PUT",
"path": "/api/v2/homes/[myzone]/zones/2/schedule/activeTimetable?ngsw-bypass=true",
"scheme": "https",
"accept": "application/json, text/plain, */*",
"accept-encoding": "gzip, deflate, br, zstd",
"accept-language": "nl,en-US;q=0.9,en;q=0.8,de;q=0.7",
"authorization": "Bearer [mytoken]",
"content-length": "8",
"origin": "https://app.tado.com",
"priority": "u=1, i",
"referer": "https://app.tado.com/",
"sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Google Chrome\";v=\"140\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
"x-amzn-trace-id": "tado=webapp-release/v3786"
}
Ich würde 200 jetzt erwarten, aber nein ... der einzige Unterschied, den ich jetzt sehe, ist das Fehlen von--data-raw , aber ich weiß nicht, wie man das integriert. Futhermore, der andere Put Aufrufe ohne es funktionieren ...
Wenn ich R.Text drucke (drucke ich.

Code: Select all

r
= https://github.com/germainlefebvre4/liB ... PI.py#l253), das ist nicht hilfreich (nicht hilfreich):

Code: Select all

{"errors":[{"code":"accessDenied","title":"current user is not allowed to access this resource"}]}
Hat jemand eine Idee, wie man dieses Verhalten behebt?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post