@@ -10,13 +10,20 @@ def raise_for_status(resp):
1010 resp ["data" ] = json .loads (resp ["data" ].decode ())
1111
1212 def handle_400 ():
13- if resp ["data" ]["error" ]["message" ] == "These users are not friends" :
14- raise NotFriendsError ("These users are not friends" )
15- elif resp ["data" ]["error" ]["message" ] == "\" Users are already friends!\" " :
16- raise AlreadyFriendsError ("Users are already friends!" )
13+ if "error" in resp ["data" ]:
14+ if resp ["data" ]["error" ]["message" ] == "These users are not friends" :
15+ raise NotFriendsError ("These users are not friends" )
16+ elif resp ["data" ]["error" ]["message" ] == "\" Users are already friends!\" " :
17+ raise AlreadyFriendsError ("Users are already friends!" )
18+ elif "verified" in resp ["data" ]:
19+ raise InvalidTwoFactorAuth ("2FactorAuth code is invalid." )
1720
1821 def handle_401 ():
19- raise IncorrectLoginError (resp ["data" ]["error" ]["message" ])
22+ if "requiresTwoFactorAuth" in resp ["data" ]["error" ]["message" ]\
23+ or "Requires Two-Factor Authentication" in resp ["data" ]["error" ]["message" ]:
24+ raise RequiresTwoFactorAuthError ("Account is 2FactorAuth protected." )
25+ elif "Invalid Username or Password" in resp ["data" ]["error" ]["message" ]:
26+ raise IncorrectLoginError (resp ["data" ]["error" ]["message" ])
2027
2128 def handle_404 ():
2229 msg = ""
@@ -37,7 +44,7 @@ def handle_404():
3744
3845 if resp ["status" ] in switch : switch [resp ["status" ]]()
3946 if resp ["status" ] != 200 : raise GeneralError ("Unhandled error occured: " + str (resp ["data" ]))
40- if "requiresTwoFactorAuth" in resp ["data" ]: raise TwoFactorAuthNotSupportedError ( "2FA is not supported yet ." )
47+ if "requiresTwoFactorAuth" in resp ["data" ]: raise RequiresTwoFactorAuthError ( "Account is 2FactorAuth protected ." )
4148
4249class ACall :
4350 def __init__ (self , loop = asyncio .get_event_loop (), verify = True ):
@@ -62,9 +69,9 @@ async def closeSession(self):
6269 await self .session .close ()
6370 self .session = None
6471
65- async def call (self , path , method = "GET" , headers = {}, params = {}, json = {}, no_auth = False ):
72+ async def call (self , path , method = "GET" , headers = {}, params = {}, json = {}, no_auth = False , verify = True ):
6673 if no_auth :
67- return await self ._call (path , method , headers , params , json )
74+ return await self ._call (path , method , headers , params , json , verify )
6875
6976 if self .apiKey == None :
7077 async with self .session .get ("https://api.vrchat.cloud/api/1/config" , verify_ssl = self .verify ) as resp :
@@ -89,19 +96,19 @@ async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth
8996 try : json = await resp .json ()
9097 except : json = None
9198
92- resp = {"status" : resp .status , "data" : json if not json == None else content }
93- raise_for_status (resp )
99+ resp = {"status" : resp .status , "response" : resp , " data" : json if not json == None else content }
100+ if verify : raise_for_status (resp )
94101 return resp
95102
96103 json = await resp .json ()
97104 status = resp .status
98105
99- resp = {"status" : status , "data" : json }
106+ resp = {"status" : status , "response" : resp , " data" : json }
100107
101- raise_for_status (resp )
108+ if verify : raise_for_status (resp )
102109 return resp
103110
104- async def _call (self , path , method = "GET" , headers = {}, params = {}, json = {}):
111+ async def _call (self , path , method = "GET" , headers = {}, params = {}, json = {}, verify = True ):
105112 h = {
106113 "user-agent" : "" ,
107114 }
@@ -132,14 +139,14 @@ async def _call(self, path, method="GET", headers={}, params={}, json={}):
132139 try : json = await resp .json ()
133140 except : json = None
134141
135- return {"status" : resp .status , "data" : json if not json == None else content }
142+ return {"status" : resp .status , "response" : resp , " data" : json if not json == None else content }
136143
137144 json = await resp .json ()
138145 status = resp .status
139146
140- resp = {"status" : status , "data" : json }
147+ resp = {"status" : status , "response" : resp , " data" : json }
141148
142- raise_for_status (resp )
149+ if verify : raise_for_status (resp )
143150 return resp
144151
145152class Call :
@@ -157,11 +164,11 @@ def new_session(self):
157164 self .session = requests .Session ()
158165 self .b64_auth = None
159166
160- def call (self , path , method = "GET" , headers = {}, params = {}, json = {}, no_auth = False ):
167+ def call (self , path , method = "GET" , headers = {}, params = {}, json = {}, no_auth = False , verify = True ):
161168 headers ["user-agent" ] = ""
162169
163170 if no_auth :
164- return self ._call (path , method , headers , params , json )
171+ return self ._call (path , method , headers , params , json , verify )
165172
166173 if self .b64_auth == None :
167174 raise NotAuthenticated ("Tried to do authenticated request without setting b64 auth (Call.set_auth(b64_auth))!" )
@@ -189,17 +196,17 @@ def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False
189196 try : json = resp .json ()
190197 except : json = None
191198
192- resp = {"status" : resp .status_code , "data" : json if not json == None else resp .content }
199+ resp = {"status" : resp .status_code , "response" : resp , " data" : json if not json == None else resp .content }
193200
194- raise_for_status (resp )
201+ if verify : raise_for_status (resp )
195202 return resp
196203
197- resp = {"status" : resp .status_code , "data" : resp .json ()}
204+ resp = {"status" : resp .status_code , "response" : resp , " data" : resp .json ()}
198205
199- raise_for_status (resp )
206+ if verify : raise_for_status (resp )
200207 return resp
201208
202- def _call (self , path , method = "GET" , headers = {}, params = {}, json = {}):
209+ def _call (self , path , method = "GET" , headers = {}, params = {}, json = {}, verify = True ):
203210 if self .apiKey == None :
204211 resp = requests .get ("https://api.vrchat.cloud/api/1/config" , headers = headers , verify = self .verify )
205212 assert resp .status_code == 200
@@ -222,12 +229,12 @@ def _call(self, path, method="GET", headers={}, params={}, json={}):
222229 try : json = resp .json ()
223230 except : json = None
224231
225- resp = {"status" : resp .status_code , "data" : json if not json == None else resp .content }
232+ resp = {"status" : resp .status_code , "response" : resp , " data" : json if not json == None else resp .content }
226233
227- raise_for_status (resp )
234+ if verify : raise_for_status (resp )
228235 return resp
229236
230- resp = {"status" : resp .status_code , "data" : resp .json ()}
237+ resp = {"status" : resp .status_code , "response" : resp , " data" : resp .json ()}
231238
232- raise_for_status (resp )
239+ if verify : raise_for_status (resp )
233240 return resp
0 commit comments