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

FileNotFoundError .config/ok/auth_refresh #348

Open
liffiton opened this issue Aug 7, 2018 · 5 comments
Open

FileNotFoundError .config/ok/auth_refresh #348

liffiton opened this issue Aug 7, 2018 · 5 comments

Comments

@liffiton
Copy link

liffiton commented Aug 7, 2018

I'm trying out okpy in a Jupyter notebook using the example data science project linked from the "Welcome to OK!" block in the front page of my course on okpy.org.

I've edited hw04.ok to point to my course's endpoint.

When I execute the first block in the notebook, I get a FileNotFoundError.

=====================================================================
Assignment: Homework 4: Probability and Sampling
OK, version v1.13.11
=====================================================================


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-9-742253450167> in <module>()
     10 from client.api.notebook import Notebook
     11 ok = Notebook('hw04.ok')
---> 12 _ = ok.auth(inline=True)

/share/apps/jhub/lib64/python3.6/site-packages/client/api/notebook.py in auth(self, force, inline)
     26         if not force and login_with_env(self.assignment):
     27             return
---> 28         self.assignment.authenticate(force=force, inline=inline)
     29 
     30     def grade(self, *args, **kwargs):

/share/apps/jhub/lib64/python3.6/site-packages/client/api/assignment.py in authenticate(self, force, inline)
    172             return auth.authenticate(self.cmd_args, endpoint=self.endpoint, force=force)
    173         else:
--> 174             return auth.notebook_authenticate(self.cmd_args, force=force)
    175 
    176     def get_student_email(self):

/share/apps/jhub/lib64/python3.6/site-packages/client/utils/auth.py in notebook_authenticate(cmd_args, force, silent)
    207     if not force:
    208         try:
--> 209             access_token = refresh_local_token(server)
    210         except OAuthException as e:
    211             # Account for Invalid Grant Error During make_token_post

/share/apps/jhub/lib64/python3.6/site-packages/client/utils/auth.py in refresh_local_token(server)
    144 def refresh_local_token(server):
    145     cur_time = int(time.time())
--> 146     access_token, expires_at, refresh_token = get_storage()
    147     if cur_time < expires_at - 10:
    148         return access_token

/share/apps/jhub/lib64/python3.6/site-packages/client/utils/auth.py in get_storage()
    118 def get_storage():
    119     create_config_directory()
--> 120     with open(REFRESH_FILE, 'rb') as fp:
    121         storage = pickle.load(fp)
    122 

FileNotFoundError: [Errno 2] No such file or directory: '/home/[...]/.config/ok/auth_refresh'

Sure enough, that file does not exist.

@Sumukh
Copy link
Member

Sumukh commented Aug 7, 2018

Interesting. Thanks for filing the issue. Could this be a permissions issue? If not, create_config_directory looks like it's broken.

As a work around could you create the ~/.config/ok/ folder and then see if it works?

@liffiton
Copy link
Author

liffiton commented Aug 7, 2018

The directory is created correctly. The code is trying to read the auth_refresh file, though, and that doesn't exist. I can create it, but then the next line fails on trying to load from an empty file. The code seems to be assuming that the auth_refresh file was created and written already, but it never was.

@Sumukh
Copy link
Member

Sumukh commented Aug 7, 2018

Odd. We'll take a look

This probably won't work but worth a shot: _ = ok.auth(inline=True, force=True)

@liffiton
Copy link
Author

liffiton commented Aug 7, 2018

It works fine with force=True. I got the prompt to get a code from okpy.org, I entered the code, and it says I've successfully logged in.

Is there some part of the logic that assumes you've authenticated previously or something?

@liffiton
Copy link
Author

If anyone runs into the same issue, I've included the following in my students' notebooks as a workaround:

import os
if not os.path.exists(os.path.join(os.environ.get("HOME"), ".config/ok/auth_refresh")):
    ok.auth(force=True)
else:
    ok.auth(inline=True)

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

2 participants