Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement refresh session / re-init #27

Open
ianklatzco opened this issue May 8, 2023 · 9 comments
Open

implement refresh session / re-init #27

ianklatzco opened this issue May 8, 2023 · 9 comments

Comments

@ianklatzco
Copy link
Owner

image

def reinit(self):

@Evalprime
Copy link

before a request is made, could prob check if the request is a 401, refresh the token if so, and then try again

@Evalprime
Copy link

by the way, you're looking for com.atproto.server.refreshSession iirc.

@MarshalX
Copy link

MarshalX commented May 18, 2023

will be resolved soon in atproto sdk MarshalX/atproto#12

@MarshalX
Copy link

it has been added in atproto sdk 0.0.6! MarshalX/atproto#27

@Scrxtchy
Copy link

@MarshalX I seem to be getting an error in 0.0.6

  File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/namespaces/sync_ns.py", line 1179, in refresh_session
 response = self._client.invoke_procedure(
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/base.py", line 69, in invoke_procedure
  return self._invoke(InvokeType.PROCEDURE, url=self._build_url(nsid), params=params, data=data, **kwargs)
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 30, in _invoke
  self._refresh_and_set_session()
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 41, in _refresh_and_set_session
   refresh_session = self.com.atproto.server.refresh_session(headers=self._get_auth_headers(self._refresh_jwt))
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/namespaces/sync_ns.py", line 1179, in refresh_session
 response = self._client.invoke_procedure(
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/base.py", line 69, in invoke_procedure
  return self._invoke(InvokeType.PROCEDURE, url=self._build_url(nsid), params=params, data=data, **kwargs)
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 30, in _invoke
  self._refresh_and_set_session()
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 41, in _refresh_and_set_session
   refresh_session = self.com.atproto.server.refresh_session(headers=self._get_auth_headers(self._refresh_jwt))
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/namespaces/sync_ns.py", line 1179, in refresh_session
 response = self._client.invoke_procedure(
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/base.py", line 69, in invoke_procedure
  return self._invoke(InvokeType.PROCEDURE, url=self._build_url(nsid), params=params, data=data, **kwargs)
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 30, in _invoke
  self._refresh_and_set_session()
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 41, in _refresh_and_set_session
   refresh_session = self.com.atproto.server.refresh_session(headers=self._get_auth_headers(self._refresh_jwt))
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/namespaces/sync_ns.py", line 1179, in refresh_session
 response = self._client.invoke_procedure(
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/base.py", line 69, in invoke_procedure
  return self._invoke(InvokeType.PROCEDURE, url=self._build_url(nsid), params=params, data=data, **kwargs)
 File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/client.py", line 29, in _invoke
  if self.me and self._should_refresh_session():
File "/mnt/mpathaf/scratch/hidden/atproto-embed/lib/python3.10/site-packages/atproto/xrpc_client/client/methods_mixin/session.py", line 12, in _should_refresh_session
   expired_at = datetime.fromtimestamp(self._access_jwt_payload.exp, tz=timezone.utc)
RecursionError: maximum recursion depth exceeded while calling a Python object

the final two lines are unique, as the stacktrace is 2000+ lines long

@MarshalX
Copy link

MarshalX commented May 20, 2023

@Scrxtchy could you show the output of

from datetime import datetime, timezone
d = datetime.now(timezone.utc)
print(d)

from the machine where you are getting the error pls

@MarshalX
Copy link

MarshalX commented May 20, 2023

ah, I think I found this bug. will be fixed asap, thank you!

@Scrxtchy
Copy link

Scrxtchy commented May 20, 2023

thanks, and if it's of any future use

>>> from datetime import datetime, timezone
d = datetime.now(timezone.utc)
print(d)>>> d = datetime.now(timezone.utc)
>>> print(d)
2023-05-20 14:30:28.278565+00:00

I should be reporting this on the right repo, sorry
I clicked the wrong linked issue from the PR

@MarshalX
Copy link

@Scrxtchy fixed in 0.0.7 (MarshalX/atproto#33). Pls let me know is everything fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants