Skip to content

Commit 01aac62

Browse files
committed
v0.17.0
1 parent 440b342 commit 01aac62

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "twscrape"
7-
version = "0.16.0"
7+
version = "0.17.0"
88
authors = [{ name = "vladkens", email = "v.pronsky@gmail.com" }]
99
description = "Twitter GraphQL and Search API implementation with SNScrape data models"
1010
readme = "readme.md"

twscrape/queue_client.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ async def get(cls, username: str, fresh=False) -> XClIdGen:
4040
tries += 1
4141
await asyncio.sleep(1)
4242

43-
raise Exception("Failed to create XClIdGen after 3 tries.")
43+
raise AbortReqError(
44+
"Faield to create XClIdGen. See: https://github.com/vladkens/twscrape/issues/248"
45+
)
4446

4547

4648
class Ctx:
@@ -53,21 +55,25 @@ async def aclose(self):
5355
await self.clt.aclose()
5456

5557
async def req(self, method: str, url: str, params: ReqParams = None) -> Response:
56-
# if code 404 on first try then generate new x-client-transaction-id and retry once
58+
# if code 404 on first try then generate new x-client-transaction-id and retry
5759
# https://github.com/vladkens/twscrape/issues/248
5860
path = urlparse(url).path or "/"
5961

60-
gen = await XClIdGenStore.get(self.acc.username)
61-
hdr = {"x-client-transaction-id": gen.calc(method, path)}
62-
rep = await self.clt.request(method, url, params=params, headers=hdr)
63-
if rep.status_code != 404:
64-
return rep
62+
tries = 0
63+
while tries < 3:
64+
gen = await XClIdGenStore.get(self.acc.username, fresh=tries > 0)
65+
hdr = {"x-client-transaction-id": gen.calc(method, path)}
66+
rep = await self.clt.request(method, url, params=params, headers=hdr)
67+
if rep.status_code != 404:
68+
return rep
6569

66-
logger.debug(f"Retrying request with new x-client-transaction-id: {url}")
70+
tries += 1
71+
logger.debug(f"Retrying request with new x-client-transaction-id: {url}")
72+
await asyncio.sleep(1)
6773

68-
gen = await XClIdGenStore.get(self.acc.username, fresh=True)
69-
hdr = {"x-client-transaction-id": gen.calc(method, path)}
70-
return await self.clt.request(method, url, params=params, headers=hdr)
74+
raise AbortReqError(
75+
"Faield to get XClIdGen. See: https://github.com/vladkens/twscrape/issues/248"
76+
)
7177

7278

7379
def req_id(rep: Response):

0 commit comments

Comments
 (0)