smkent / safeway-coupons

🥫 🎫 Automatic coupon clipper for Safeway's online "Safeway for U" coupons
GNU General Public License v3.0
58 stars 17 forks source link

Unable to login #20

Closed Allmight3 closed 4 years ago

Allmight3 commented 4 years ago

The original error that comes up:

Exception: Expecting value: line 1 column 1 (char 0) Traceback (most recent call last): File "safeway-coupons.py", line 96, in init self._login() File "safeway-coupons.py", line 185, in _login rsp_data = json.loads(rsp.content.decode('UTF-8')) File "C:\Python3\lib\json__init__.py", line 348, in loads return _default_decoder.decode(s) File "C:\Python3\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python3\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I took a look at why there was a JSON error and it appears that there is no longer a successful request being sent to login. Here is a print of the rsp.content:

b''

I'm using the latest commit I see from Feb 19 and I am using python 3.7.5.

jillh510 commented 4 years ago

I'm seeing the same thing. 403 error returned from the call to rsp = self._run_request(('https://www.safeway.com/iaaw/service/' 'authenticate'), json_data=login_data, headers=headers)

smkent commented 4 years ago

It appears Safeway has started using Okta for login (the login form now posts to albertsons.okta.com). I'll need to do some investigation.

jamesderlin commented 4 years ago

Any update? Does the new system use a captcha?

Allmight3 commented 4 years ago

@jamesderlin for now I am just using a headless selenium chrome browser to clip them.

Not as nice but it'll have to do until @smkent has a chance to fix the login.

jmacknet commented 4 years ago

Looks like somebody figured it out. I may try to merge the new auth part.

https://blog.jonlu.ca/posts/safeway

jmacknet commented 4 years ago

Just created PR #21 that updates for the new authentication method. It's basically as described in the previous link, though the blog post glossed over many critical details.

tieubao81 commented 4 years ago

I'm not sure if deleting ORIGIN completely did the trick. It was able to clip, but not all. I visited the safeway J4U website and there's still a lot of unclipped coupons. Especially in the Personalized Price and Special Offer. After you click load more, it seems to stopped clipping those coupons all together.

jmacknet commented 4 years ago

@tieubao81, I think there's a secondary issue with an API change. The new URL for the coupon gallery is https://www.safeway.com/abs/pub/web/j4u/api/ecomgallery, and it has a different JSON format. I initially reworked the code to use the new ecomgallery URL before finding out that the old URL still worked with the ORIGIN header removed. I thought all the coupons were being clipped with the old URL, but it looks like they may not be if you're still getting unclipped coupons. It's not hard to switch to the new URL, just a couple minor changes to address the new JSON layout.

jmacknet commented 4 years ago

Took another look at the unclipped coupons and it looks like they are actually being clipped, but show up as unclipped on the browser due to the new use of localstorage caching of the coupon list. To force the cache to clear, I deleted all my cookies and logged in again and the coupons that were previously showing unclipped were actually clipped. So I think the coupon clipper is working fine.

machowsk commented 4 years ago

For what it's worth, I pulled @jmacknet's Okta changes in PR21 into my fork of this project and it's working fine. Thanks, jmacknet!

smkent commented 4 years ago

Thanks to @jmacknet for providing a fix in #21!