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

Commit

Permalink
Retry logic (specificly when vrc disconnects request)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katistic committed Oct 4, 2020
1 parent 3aaa566 commit adb2e23
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions vrcpy/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from vrcpy.errors import *


call_retries = 1


def raise_for_status(resp):
if type(resp["data"]) == bytes:
resp["data"] = json.loads(resp["data"].decode())
Expand Down Expand Up @@ -80,7 +83,19 @@ async def closeSession(self):
await self.session.close()
self.session = None

async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True, retries=None):
for tri in range(0, (retries or call_retries) + 1):
try:
resp = await self._call_wrap(path, method, headers, params, json, no_auth, verify)
break
except requests.exceptions.ConnectionError as e: # Gosh darnit VRC team, why've you done this!
if tri == (retries or call_retries):
raise requests.exceptions.ConnectionError(
str(e) + " ({} retries)".format(retries))

return resp

async def _call_wrap(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
if no_auth:
return await self._call(path, method, headers, params, json, verify)

Expand Down Expand Up @@ -188,7 +203,19 @@ def new_session(self):
self.session = requests.Session()
self.b64_auth = None

def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True, retries=None):
for tri in range(0, (retries or call_retries) + 1):
try:
resp = self._call_wrap(path, method, headers, params, json, no_auth, verify)
break
except requests.exceptions.ConnectionError as e: # Gosh darnit VRC team, why've you done this!
if tri == (retries or call_retries):
raise requests.exceptions.ConnectionError(
str(e) + " ({} retries)".format(retries))

return resp

def _call_wrap(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True):
headers["user-agent"] = ""

if no_auth:
Expand Down

0 comments on commit adb2e23

Please sign in to comment.