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

AttributeError: 'Service' object has no attribute 'groups' #3217

Closed
m-mayran opened this issue Oct 20, 2020 · 3 comments · Fixed by #3293
Closed

AttributeError: 'Service' object has no attribute 'groups' #3217

m-mayran opened this issue Oct 20, 2020 · 3 comments · Fixed by #3293
Labels

Comments

@m-mayran
Copy link

m-mayran commented Oct 20, 2020

Hi,
[Running 1.2.0b1]

I am running the following code in a service to get information about my user:

import requests
api_url = os.environ['JUPYTERHUB_API_URL']
api_token = os.environ['JUPYTERHUB_API_TOKEN']
r = requests.get(api_url + '/user', headers={'Authorization': 'token %s' % api_token,})

The request seems to authenticate ok (I would get a 403 if I put /users for example) but it returns the following:

Uncaught exception GET /hub/api/user (172.17.0.2)
    HTTPServerRequest(protocol='http', host='172.17.0.2:8081', method='GET', uri='/hub/api/user', version='HTTP/1.1', remote_ip='172.17.0.2')
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/dist-packages/tornado/web.py", line 1703, in _execute
        result = await result
      File "/usr/local/lib/python3.6/dist-packages/jupyterhub/apihandlers/users.py", line 38, in get
        self.write(json.dumps(self.user_model(user)))
      File "/usr/local/lib/python3.6/dist-packages/jupyterhub/apihandlers/base.py", line 193, in user_model
        'groups': [g.name for g in user.groups],
    AttributeError: 'Service' object has no attribute 'groups'
@m-mayran m-mayran added the bug label Oct 20, 2020
@welcome
Copy link

welcome bot commented Oct 20, 2020

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@Kangsan-Jeon
Copy link

I had a same issue, when I called /user GET API.
Another API(/users GET, /users/{name}/tokens GET, etc.) were operated well except above API.
In my case, users were authenticated by LDAP.

@minrk
Copy link
Member

minrk commented Dec 2, 2020

This should fail with 403 as it is now, but we can also make it work for services. The request being made here is asking to identify the service itself, not your user. If you want information about your users, it should send the oauth token associated with the user accessing your service, not the service's token itself.

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

Successfully merging a pull request may close this issue.

3 participants