Getting Django error 'AnonymousUser' object is not iterable after redirecting back from Stripe page

时光怂恿深爱的人放手 提交于 2019-12-25 01:39:51

问题


So it is my understanding that this error comes about from trying to call request.user when a user isn't logged in. The problem I'm having is, I am using Stripe Connect Express so I can have users sign up with debit card or bank account for payouts in my marketplace app. This redirects the user to stripe for a few pages. When Stripe collects the data it needs it redirects the user back to my page where I use request.user to pull their info from the database so I can save Stripe data to their table.

I'd say about 50% of the time this is successful and the other half I get the error

TypeError at /pricing/ 'AnonymousUser' object is not iterable

This leads me to believe that the user is logged out sometime during the redirect to Stripe. Is there a solution to this issue? Is my session expired? Did the CSRF token change?

Also, Stripe allows you to pass a 'state' query parameter in the POST request to them which they suggest to is for matters like CSRF tokens. They then return this 'state' to you in the redirect GET request they send from their servers. Can I take this information to possibly fix my issue?


回答1:


I think I found the answer here. I originally had my redirect uri listed on Stripe as 127.0.0.1...but I have been developing in localhost assuming it just abstracted the aforementioned - but apparently it may've been creating 2 different cookies. Been through a bunch of test cases so far and seems to have fixed it.



来源:https://stackoverflow.com/questions/50356951/getting-django-error-anonymoususer-object-is-not-iterable-after-redirecting-ba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!