bernd-wechner / Degoo

CLI tool(s) for working with Degoo cloud storage
Other
143 stars 41 forks source link

Fix login issue #25 #27

Closed squidharth closed 2 years ago

squidharth commented 2 years ago

Updated the login function to fix user login failure.

bernd-wechner commented 2 years ago

Thank you so much for this! I will close the PR, only because I had local changes already implementing most of it, and in fact the only difference between what you've submitted and I had are:

  1. The User Agent
  2. The OrderedDict

I tested it and it seems not sensitive to OrderedDict (but that could be a coincidence that Dict maintained the order - which it does not guaranteed) so I've kept your orderedDict.

The User Agent is a stroke of genius and I would like to ask how you found it. Reason I ask is I have sniffed the whole login process from Chrome and duplicated the User agent it submits and this continues to failed. But the User agent you have identified here works, I just haven't seen it in practice sniffing any of the Degoo Web interactions. So I'm wonderig where I missed it and how you found it!

I have pushed these fixes to this repo (and they are almost identical to your PR).

squidharth commented 2 years ago

The value for User-Agent is arbitrary. I made it up. You are free to change it to whatever you like. I suspect that it is not the actual value that is the reason for the failure but the order in which it appeared in the final request. In my analysis, the User-Agent header must be second in order in the HTTP request ('Host' being the first one in the case of HTTP/1.1. requests is smart enough to insert this on our behalf).

I read somewhere that Python3 uses ordered dictionary by default in its collections. That may be the reason why you are able to get way with not using collections.OrderedDict. However, I recommend using the OrderedDict explictly to ensure that the order is preserved. Its sad that we have to do this; it's a flagrant disregard for the HTTP specification; but we are at their mercy :(

Happy to help. Keep up the great work!

bernd-wechner commented 2 years ago

Good to know. I was replicating as exactly as possible the User-Agent that the browser submitted. No idea why that was failing.

You're right dicts are ordered as of Python 3.7 (and I use 3.8):

https://mail.python.org/pipermail/python-dev/2017-December/151283.html

so order is unlikely to be the problem. That said to keep it compatible with pre 3.7 specs it indeed best to use an OrderedDict (and that is implemented in the current commit on master).

Alas we are at Degoo's mercy as I have asked them to publish an API with no luck so far.

I was experimenting with fiddler to see if I could sniff what the Python actually sends. Not luck yet (haven't given it any time in ages) So that snipped of code has a little if fiddler section with a hard coded flag for experimenting. As far as I could tell I was configuring the exact same HTTP request that my browser sent. My browser logged in successfully, but the Python client not. Hence my desire to see the raw request Python was sending (at the outgoing end not my configuration end). Which is where fiddler can play a role. Though any on-line service that reflect HTTP requests as plain text exactly as received would serve, but I can't find one, and writing one is another job.