[ka6] fix connecteur gruo.ca (1/2): ré-application (3e fois) du fix 401 Shopify perdu — aa2e926 (_StorefrontLockedError sur HTTP 401 direct et « upstream 401 » Scrapfly, catalogue vide fidèle à la source pour les storefronts verrouillés) annulé par le revert 28491c6 de la vague de Reverts des sessions concurrentes; shopify.py re-patché à l'identique via git apply --3way de aa2e926. Requis pour gruo.ca qui vient de migrer WooCommerce → Shopify en mode « Launching soon » (storefront password)
1 changed file +14 −0
modified
fabrika/connectors/shopify.py
+14 −0
@@ -26,6 +26,12 @@ class _PageCapError(RuntimeError): | ||
| 26 | 26 | une panne (ex. qublivre.ca, >25 k livres).""" |
| 27 | 27 | |
| 28 | 28 | |
| 29 | +class _StorefrontLockedError(RuntimeError): | |
| 30 | + """HTTP 401 sur /products.json : storefront verrouillé par mot de passe | |
| 31 | + (mode « Bientôt ouvert », ex. fermeail-land.com) — rien n'est vendu | |
| 32 | + publiquement, catalogue vide fidèle à la source, pas une panne.""" | |
| 33 | + | |
| 34 | + | |
| 29 | 35 | class ShopifyConnector(BaseConnector): |
| 30 | 36 | platform = "shopify" |
| 31 | 37 | |
@@ -70,6 +76,8 @@ class ShopifyConnector(BaseConnector): | ||
| 70 | 76 | last_err = RuntimeError("429 Too Many Requests") |
| 71 | 77 | elif code == "400": |
| 72 | 78 | raise _PageCapError(f"HTTP 400 {url}") |
| 79 | + elif code == "401": | |
| 80 | + raise _StorefrontLockedError(f"HTTP 401 {url}") | |
| 73 | 81 | else: |
| 74 | 82 | last_err = RuntimeError(f"HTTP {code or 'error'} {p.stderr[:120]}") |
| 75 | 83 | time.sleep(2) |
@@ -80,6 +88,8 @@ class ShopifyConnector(BaseConnector): | ||
| 80 | 88 | data = self._scrapfly_json(url) |
| 81 | 89 | self._scrapfly_only = True |
| 82 | 90 | return data |
| 91 | + except (_PageCapError, _StorefrontLockedError): | |
| 92 | + raise | |
| 83 | 93 | except Exception as exc: |
| 84 | 94 | last_err = exc |
| 85 | 95 | raise RuntimeError(f"{url}: {last_err}") |
@@ -94,6 +104,8 @@ class ShopifyConnector(BaseConnector): | ||
| 94 | 104 | except Exception as exc: |
| 95 | 105 | if "upstream 400" in str(exc): |
| 96 | 106 | raise _PageCapError(str(exc)) from exc |
| 107 | + if "upstream 401" in str(exc): | |
| 108 | + raise _StorefrontLockedError(str(exc)) from exc | |
| 97 | 109 | last_err = exc |
| 98 | 110 | time.sleep(3 * (attempt + 1)) |
| 99 | 111 | raise RuntimeError(f"{url}: scrapfly: {last_err}") |
@@ -108,6 +120,8 @@ class ShopifyConnector(BaseConnector): | ||
| 108 | 120 | if page > 1 and out: |
| 109 | 121 | break |
| 110 | 122 | raise |
| 123 | + except _StorefrontLockedError: | |
| 124 | + break | |
| 111 | 125 | items = data.get("products", []) |
| 112 | 126 | if not items: |
| 113 | 127 | break |
| 114 | 128 | |