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

api authentication is not working #460

Closed
jaydip189 opened this issue Mar 12, 2018 · 28 comments
Closed

api authentication is not working #460

jaydip189 opened this issue Mar 12, 2018 · 28 comments

Comments

@jaydip189
Copy link

jaydip189 commented Mar 12, 2018

api call is not working.

File "auth.py", line 3, in
import gitlab
File "D:\DevOps\gitlab\gitlab.py", line 17, in
g1()
File "D:\DevOps\gitlab\gitlab.py", line 10, in g1
gl = gitlab.Gitlab('http://gitlab.com', oauth_token='rUAuB2dWFxccvbbd')
AttributeError: module 'gitlab' has no attribute 'Gitlab'

In page: api-usage.rst

@gpocentek
Copy link
Contributor

Hi @jaydip189

It looks like an import conflict. Rename your gitlab.py to something else and it should work.

@jaydip189
Copy link
Author

Hi @gpocentek

Renamed auth.py but some how api authentication is not working.I want to create project dynamically.

#!/usr/bin/env python
import gitlab

class gitlab(object):

def g1(self,g1):

  gl = gitlab('https://gitlab.com/', private_token='rUAuB2dWFb')
  g1.auth()

@gpocentek
Copy link
Contributor

You need to use:

gl = gitlab.Gitlab('https://gitlab.com/', private_token='...')

@jaydip189
Copy link
Author

jaydip189 commented Mar 12, 2018

@gpocentek but it's unable to fetch gitlab attributes like (e.g create project , create repo)

@gpocentek
Copy link
Contributor

@jaydip189 Could you provide a complete code example that I could use to reproduce the error? And also provide the complete error you're getting.

Without this information I won't be able to help. Thank you.

@jaydip189
Copy link
Author

@gpocentek please help me outta of this.I need to only api authentication with github (private token)

This is the entire code of python and getting error AttributeError: module 'gitlab' has no attribute 'Gitlab'
#!/usr/bin/env python

import gitlab

def g1():

gl = gitlab.Gitlab('http://gitlab.com', private_token='xxxxxxxxxx')
g1.auth()

projects = gl.projects.list()
for project in projects:
print(project)

def g1():
print ('Create Project')
print ('Create repo')

def projects():
projects = gl.projects.list(visibility='public')

g1()
projects()

@gpocentek
Copy link
Contributor

gpocentek commented Mar 12, 2018

AttributeError: module 'gitlab' has no attribute 'Gitlab': You still have an import problem. You can try this to see which file is imported:

$ python
Python 2.7.14 (default, Sep 23 2017, 22:06:14) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gitlab
>>> gitlab
<module 'gitlab' from '/usr/lib/python2.7/dist-packages/gitlab/__init__.pyc'>
>>>

Make sure that the path displayed is the __init__.py file of the gitlab package, not a file you have written yourself.

@jaydip189
Copy link
Author

jaydip189 commented Mar 12, 2018

(venv) λ python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import gitlab
gitlab
<module 'gitlab' from 'D:\DevOps\gitlab\venv\lib\site-packages\gitlab\init.py'>

@gpocentek
Copy link
Contributor

gpocentek commented Mar 12, 2018

What does gitlab.Gitlab return in the python shell?

@jaydip189
Copy link
Author

g1.auth()
Traceback (most recent call last):
File "", line 1, in
NameError: name 'g1' is not defined

@gpocentek
Copy link
Contributor

gitlab.Gitlab is trying to execute your own code. I don't know what's happening there, but this is not a python-gitlab problem.

The only thing I can think of is that you still have a gitlab.pyc, gitlab.py or gitlab.pyo file somewhere.

@jaydip189
Copy link
Author

need to declare variable of g1 right?

@jaydip189
Copy link
Author

@gpocentek gitlab api connection is working fine now.Thanks for your help.

@jaydip189
Copy link
Author

#!/usr/bin/env python
import gitlab

class gitlab(object):

def g1(self):

gl = gitlab.Gitlab('http://gitlab.com', private_token='3xxxxx')
g1.auth()
gl.projects.list()

class projects(object):
def projects(self):
projects = gl.projects.list ( )
for project in projects:
print (projects)

@jaydip189
Copy link
Author

jaydip189 commented Mar 12, 2018

@gpocentek In python shell I'm getting output of project list , groups .but however i'm not getting output when i'm running program.I think projects method will not invoking.

@jaydip189
Copy link
Author

I'm calling g1.project.create() method,it gives argument passing error.what i need to pass in argument.

@gpocentek
Copy link
Contributor

You can find project creation examples in the documentation: http://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html

@jaydip189
Copy link
Author

project = gl.projects.create({'name': 'project1'}) is not working.it gives data argument error.

File "test.py", line 32, in
gitlab_projects = glab.create_projects()
File "test.py", line 23, in create_projects
return self.gitlab_client.projects.create ( )
File "C:\Users\jaydipsinh.jadeja\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gitlab\exceptions.py", line 251, in wrapped_f
return f(*args, **kwargs)
TypeError: create() missing 1 required positional argument: 'data'

@gpocentek
Copy link
Contributor

I recommend you start with learning python because you are clearly not familiar with the language.

You are facing beginner issues which have nothing to do with python-gitlab.

I don't have the time to help you learn python.

@jaydip189
Copy link
Author

Thanks for your help.I will learn python and get back to you if facing any issue with python-gitlab.

@kitten77
Copy link

kitten77 commented Dec 7, 2018

Gitlab version 1.0.2
Python 3.7.1 (default, Oct 21 2018, 08:03:53)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import gitlab
gitlab
<module 'gitlab' from '/home/muad/workbench/gitlab/slickgear/venv_3.7/lib/python3.7/site-packages/gitlab/init.py'>
gitlab.Gitlab()
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'gitlab' has no attribute 'Gitlab'

just bumped into this one, any ideas what is happening here?

@puzza007
Copy link

@kitten77 make sure you've installed python-gitlab rather than gitlab

@kitten77
Copy link

Yeah i found that, maybe this is something that should be fixed by renaming the Gitlab() class to PyGitlab() and return a warning deprecated use PyGitlab() ? Just a thought

@graham-macleod
Copy link

The issue I had was the python script I was testing with was called gitlab.py. Obiously, if you try to "import gitlab" then your script is going to import itself. Never call the script you're writing the same thing as what you're trying to import.

@skbly7
Copy link

skbly7 commented Oct 3, 2019

This happened with me as well, and I did the follows:

pip install gitlab
pip install python-gitlab
pip uninstall gitlab

But the code wasn't working even after removal of gitlab package. In this case, you need to uninstall and install the python-gitlab again. Not sure why though. I am assuming related to how these packages are setting up after installation might be conflicting in nature.

pip uninstall python-gitlab
pip install python-gitlab

@bufferoverflow
Copy link
Member

I've just written the following to the maintainer of gitlab package:

Hi Yoginth

We face conflicts with your Python package gitlab, see https://github.com/python-gitlab/python-gitlab/issues/460#issuecomment-537837892

Do you still maintain that?
If not do you see an option to transfer the name on pypi to the maintainers of python-gitlab to avoid such issues?

Best
Roger

@itmeryn
Copy link

itmeryn commented Oct 21, 2019

rename filename myGitlab if name is gitlab , error is show

@coffeepenbit
Copy link

@kitten77 make sure you've installed python-gitlab rather than gitlab

This solved the issue for me. Thanks.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants