user.get_likes() throw an ERROR
jiangzc opened this issue · comments
the method "user.get_likes()" throw an error: "requests.exceptions.TooManyRedirects"
I checked the url "http://tieba.baidu.com/f/like/mylike?pn=1"
The results are listed below
pull request : fixed the BUG
Analysis
There are only 3 redirections in my Browser, however, the method throw an error: "requests.exceptions.TooManyRedirects".
I disabled auto-redirect of requests.Session.get() and surprisedly found the redirections are in a LOOP!
A => B => C => A
Then I consulted some information on Baidu Tieba. Someone says a field named "STOKEN" caused the problem. But why my Browser works well while my program are trapped in a LOOP ?
After a careful consideration, I got the answer. It seems that requests Lib redirects first rather than Set-Cookie. As a result of missing "STOKEN", Baidu leads the program to get Cookie by redirection endlessly.
Solution
Disable auto-redirect and get "Location" field of each Respond. After 2 Responds, you can get "STOKEN".