Reputation: 273
I am trying to read the file from gitlab. I created access token in gitlab for this. Downloaded module python-gitlab
I installed module python-gitlab from PyCharm: File --> Settings--> Python interpreter --> python-gitlab
import gitlab
import json
from pprint import pprint
import requests
import urllib.request
# private token authentication
gl = gitlab.Gitlab('https://gitlab.com/..../CSV_HOMEWORK.csv', private_token='xxx')
gl.auth()
# list all projects
projects = gl.projects.list()
for project in projects:
# print(project) # prints all the meta data for the project
print("Project: ", project.name)
print("Gitlab URL: ", project.http_url_to_repo)
# print("Branches: ", project.repo_branches)
pprint(project.repository_tree(all=True))
f = urllib.request.urlopen(project.http_url_to_repo)
myfile = f.read()
print(myfile)
print("\n\n")
P.S. My file name from where I run my code isn't gitlab.py
Upvotes: 5
Views: 8631
Reputation: 40871
You installed the package gitlab
instead of python-gitlab
.
Even if you installed python-gitlab
already, the gitlab
package will still conflict, so it must be uninstalled
pip uninstall gitlab
pip install python-gitlab
This is evidenced by the path identified in the error, pointing to a different package in site-packages
. If you inspect the files in this path, you'll find it's not those expected to be contained in the python-gitlab
package.
Similar problems (not necessarily in this case) may be caused in a circumstance where you've named a module gitlab.py
or named a package directory within your project gitlab/
.
Upvotes: 8
Reputation: 1781
The issue can also happen when the file is gitlab.py
. Renaming the file will solve the issue, when the package is not conflicting with gitlab
.
Upvotes: 2
Reputation: 8652
Posting @kaymaz' comment into an answer so future readers can discover a potential solution more easily:
When your file is named gitlab.py it imports itself instead of the gitlab (or python-gitlab) module. Therefore the above error message appears. Rename the file to something else and it'll work.
Upvotes: 0
Reputation: 11
It worked for me after I uninstalled both packages and reinstalled the python-gitlab
package.
pip uninstall gitlab
pip uninstall python-gitlab
pip install python-gitlab
Upvotes: 1