biemster / FindMy

Query Apple's Find My network
225 stars 39 forks source link

400 Bad Request #20

Closed davesenior9 closed 8 months ago

davesenior9 commented 1 year ago
400 Bad Request
Traceback (most recent call last):
  File "request_reports.py", line 189, in <module>
    res = json.loads(response.read())['results']
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Have you encountered this before? I have automated the polling of this script, and had it running for a few days. It abruptly stopped and generated this error. Restarting the script made no change. If i go back to vanilla OHS and use the GUI, it updates fine.

Thanks!

Additional Info drawn from response headers.

[('content-length', '0'), ('via', 'xrail:st53p00ic-qujn14040502.me.com:8301:22R920:grp60,631194250daa17e24277dea86cf30319:0299c4cf8819616e8ba5700c89695c8d:jptyo12'), ('access-control-expose-headers', 'X-Apple-Request-UUID,Via'), ('strict-transport-security', 'max-age=31536000; includeSubDomains;'), ('x-responding-instance', 'acsnservice:2:prod-p00-acsnservice--partial-5b7df67f59-sx8n8:80:2388B9802:6a2bc5323182'), ('server', 'AppleHttpServer/3faf4ee9434b'), ('x-apple-jingle-correlation-key', '<removed>'), ('connection', 'keep-alive'), ('apple-seq', '0'), ('x-apple-user-partition', '0'), ('date', 'Thu, 30 Mar 2023 01:23:32 GMT'), ('x-apple-request-uuid', '<removed>'), ('apple-tk', 'false'), ('apple-originating-system', 'UnknownOriginatingSystem'), ('x-apple-edge-response-time', '168')]
EbonyHuang commented 1 year ago

We see the same issue here. If you print out response.status and response.reason, it shows that 400 Bad Request. This seems mean the incorrect header/data is posted to server. But why it happened?? Not sure what's wrong???

biemster commented 1 year ago

Odd stuff! What OS are you on @davesenior9 and @EbonyHuang ? I'll have to spin up my macOS dockers to see if I can reproduce. Do both the request_reports.py and FindMy_client.py fail for you? (it might be related to the startDate and endDate fields, I've noticed some server-side changes in that area).

EbonyHuang commented 1 year ago

For both BigSur and Monterey OS, the request_report.py has the same failure. It all works couple days ago. Thank you.

EbonyHuang commented 1 year ago

Looks like it is the https body(search) contain the single quote ' in the "ids" list, when we replace that single quote to be double ". It seems work again. add this line before do the https post. data = data.replace("'",'"')

davesenior9 commented 1 year ago

awesome work. thats fixed it for me. I would be interested to know what caused this. Some sort of change on the Apple gateway?

biemster commented 1 year ago

Well done @EbonyHuang ! The ids list was a bit hacky indeed, I guess Apple updated a json parser somewhere, not allowing single quotes anymore. I'll put in a fix when I find the time.

biemster commented 1 year ago

Reopening because this definitely needs the fix by @EbonyHuang

mrx23dot commented 1 year ago

got the same issue, response was 0 len i think it fails in

    def do_OPTIONS(self):
        self.send_response(200, "ok")

before def do_POST(self): is called

had to replace six with flask.

biemster commented 1 year ago

@mrx23dot the fix is already given in https://github.com/biemster/FindMy/issues/20#issuecomment-1490910909, I just need to push that to the repo. In the meantime you can just add that in your clone.

biemster commented 8 months ago

This should be fixed now in both the catalina and monterey branches. Also main of course but that is undergoing major overhaul at the moment, to abolish the requirement of a mac altogether.