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

Gitlab plugin fails with TypeError #168

Closed
rkratky opened this issue Dec 8, 2018 · 6 comments
Closed

Gitlab plugin fails with TypeError #168

rkratky opened this issue Dec 8, 2018 · 6 comments
Assignees

Comments

@rkratky
Copy link

rkratky commented Dec 8, 2018

The following configuration:

[general]
email = <username>@redhat.com,<username>@gmail.com
width = 0

[gitlab]
type = gitlab
url = https://gitlab.com/
token = <token>
login = <username>
ssl_verify = true

results in:

 DEBUG  Query: users?username=<username>
Traceback (most recent call last):
  File "/usr/bin/did", line 4, in <module>
    __import__('pkg_resources').run_script('did==0.11.1', 'did')
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 661, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1441, in run_script
    exec(code, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/EGG-INFO/scripts/did", line 42, in <module>
    did.cli.main()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/cli.py", line 198, in main
    user_stats.check()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/stats.py", line 136, in check
    stat.check()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/stats.py", line 136, in check
    stat.check()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/stats.py", line 79, in check
    self.fetch()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 211, in fetch
    'Issue', 'opened')
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 140, in search
    self.user = self.get_user(user)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 92, in get_user
    result = self._get_gitlab_api_json(query)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 67, in _get_gitlab_api_json
    result = self._get_gitlab_api(endpoint).json()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 63, in _get_gitlab_api
    return self._get_gitlab_api_raw(url)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 59, in _get_gitlab_api_raw
    return requests.get(url, headers=self.headers, verify=self.ssl_verify)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 416, in send
    self.cert_verify(conn, request.url, verify, cert)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 226, in cert_verify
    if not cert_loc or not os.path.exists(cert_loc):
  File "/usr/lib64/python2.7/genericpath.py", line 26, in exists
    os.stat(path)
TypeError: coercing to Unicode: need string or buffer, int found

Tried with multiple different Gitlab instances, but the result is always the same.

When I comment out ssl_verify = true, then it appears to work, but only if there's no activity. If there is something to report, it fails with:

 INFO  Searching for Merge requests created by <username>@redhat.com
 DEBUG  Result: 1 item fetched
 DEBUG  Query: projects/<project>
Traceback (most recent call last):
  File "/usr/bin/did", line 4, in <module>
    __import__('pkg_resources').run_script('did==0.11.1', 'did')
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 661, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1441, in run_script
    exec(code, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/EGG-INFO/scripts/did", line 42, in <module>
    did.cli.main()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/cli.py", line 198, in main
    user_stats.check()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/stats.py", line 136, in check
    stat.check()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/stats.py", line 136, in check
    stat.check()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/stats.py", line 79, in check
    self.fetch()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 254, in fetch
    for mr in results]
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 164, in __init__
    self.id = self.iid()
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 182, in iid
    self.data['project_id'], self.data['target_id'])['iid']
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 106, in get_project_mr
    mrs = self.get_project_mrs(project_id)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 114, in get_project_mrs
    query, get_all_results=True)
  File "/usr/lib/python2.7/site-packages/did-0.11.1-py2.7.egg/did/plugins/gitlab.py", line 75, in _get_gitlab_api_list
    result.raise_for_status()
  File "/usr/lib/python2.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://gitlab.com/api/v4/projects/<project>/merge_requests

My address on gitlab.com is @gmail.com, but notice that it fails already during the run with @redhat.com.

did version:

commit 3c34c94467892fe497d96386b3794847d6b0a34a
Author: Petr Šplíchal <[email protected]>
Date:   Fri Dec 7 19:35:54 2018 +0100
@psss psss self-assigned this Dec 19, 2018
@psss
Copy link
Owner

psss commented Dec 19, 2018

It seems that you are not using a valid username:

[ DEBUG ] Query: users?username=<username>
[ INFO ] Searching for Merge requests created by <username>@redhat.com

You should provide an existing user in the config, for example:

login = rkratky

Or omit it from the config altogether, then it would be detected from the email address. Does that help?

@rkratky
Copy link
Author

rkratky commented Dec 19, 2018

Out of habit, I substituted he username in the config and output copied to this issue. When running, the config is correct, and the output reflects the use of the 'rkratky' username (regardless of whether I omit it and rely on the email address, or configure it explicitly using the login parameter). This is not the cause of the problem.

@psss
Copy link
Owner

psss commented Dec 19, 2018

I was able to reproduce a similar error by creating an access token with read_user only scope. Have you checked api scope when creating the access token?

@rkratky
Copy link
Author

rkratky commented Dec 19, 2018

Honestly, I don't know what constitutes api scope on GitHub because it's not mentioned anywhere among the options for new tokens. But granting all rights except repo deletion seems to have fixed the problem on GH. Thanks!

Unfortunately, not on GitLab. There, I have a token with 'API' access, but I'm still getting the TypeError. I tried with a freshly generated token and updated did but still the same.

@psss
Copy link
Owner

psss commented Dec 19, 2018

We should clearly specify the GitLab scope in the documentation: 4bcc705. So you get the TypeError even with the token correctly set up and option ssl_verify completely removed from the config? Is the traceback identical to the first one you pasted?

@rkratky
Copy link
Author

rkratky commented Dec 19, 2018

So you get the TypeError even with the token correctly set up and option ssl_verify completely removed from the config?

No, when I remove it from Gitlab settings, it works. (It works with it for GitHub.) Before, it worked if there was no activity during the reported period. With the correct token, it works.

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

No branches or pull requests

2 participants