Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit adb2e23

Browse files
committed
Retry logic (specificly when vrc disconnects request)
1 parent 3aaa566 commit adb2e23

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

vrcpy/request.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from vrcpy.errors import *
77

88

9+
call_retries = 1
10+
11+
912
def raise_for_status(resp):
1013
if type(resp["data"]) == bytes:
1114
resp["data"] = json.loads(resp["data"].decode())
@@ -80,7 +83,19 @@ async def closeSession(self):
8083
await self.session.close()
8184
self.session = None
8285

83-
async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
86+
async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True, retries=None):
87+
for tri in range(0, (retries or call_retries) + 1):
88+
try:
89+
resp = await self._call_wrap(path, method, headers, params, json, no_auth, verify)
90+
break
91+
except requests.exceptions.ConnectionError as e: # Gosh darnit VRC team, why've you done this!
92+
if tri == (retries or call_retries):
93+
raise requests.exceptions.ConnectionError(
94+
str(e) + " ({} retries)".format(retries))
95+
96+
return resp
97+
98+
async def _call_wrap(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
8499
if no_auth:
85100
return await self._call(path, method, headers, params, json, verify)
86101

@@ -188,7 +203,19 @@ def new_session(self):
188203
self.session = requests.Session()
189204
self.b64_auth = None
190205

191-
def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
206+
def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True, retries=None):
207+
for tri in range(0, (retries or call_retries) + 1):
208+
try:
209+
resp = self._call_wrap(path, method, headers, params, json, no_auth, verify)
210+
break
211+
except requests.exceptions.ConnectionError as e: # Gosh darnit VRC team, why've you done this!
212+
if tri == (retries or call_retries):
213+
raise requests.exceptions.ConnectionError(
214+
str(e) + " ({} retries)".format(retries))
215+
216+
return resp
217+
218+
def _call_wrap(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
192219
headers["user-agent"] = ""
193220

194221
if no_auth:

0 commit comments

Comments
 (0)