Connect to an gitlab user - python

i would like to connect to a user in my gitlab server.
i connect to the gitlab server:
import gitlab
gl = gitlab.Gitlab('http://10.0.0.120')
print(gl.users.list())
the connect to the server not getting me any errors but after adding the line:
print(gl.users.list())
i get this error:
raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabListError: 403: 403 Forbidden - Not authorized to access /api/v4/users
how can i fix this?
thanks.

Usually, we use the terminal to connect to gitlab users. You can follow the following steps:
Call the terminal with "ctrl+~" in vscode
Use command git init
Configure user name and mailbox:
git config --global user.name “user.name"
git config --global user.email "user.email"

Related

SMTPServerDisconnected When Sending via Flask-Mail on Gunicorn

I have a Flask app deployed with Gunicorn & Nginx and I am trying to debug a strange issue I am having with sending emails from the application (via Flask-Mail library). Sending emails works from my local development environment and also works on my server (on Digital Ocean) if I start my application via the flask run command. This is important as most of the answers I have found mention that their hosting provider blocks outgoing mail over the default SMTP port.
Once I try to send any email from the application hosted in Gunicorn I get the following error in my logs -
File "/usr/lib/python3.10/smtplib.py", line 365, in send
raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
My application is launched in Gunicorn via the below command -
gunicorn --workers 3 \
--timeout 120 \
--bind 0.0.0.0:9000 \
--log-file=dt.log \
--bind unix:dt.sock -m 007 \
--log-level=info wsgi:app
I have created a very simple route to send an email and I see the same behavior as my existing code. This is the route I created.
#bp.route("/debugmail")
def debugmail():
msg = Message(
"An Email Subject!",
sender=("Email Sender Name", "emailfromsample#gmail.com"),
recipients=["ping#pong.com"],
)
msg.body = "This is an email from the App (tons of uses for this)."
# Also Tried Adding the Connect Command Here
# mail.connect()
mail.send(msg)
return {"message": "Email sent!"}, 200
The configuration file I use for this app is below -
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_USE_SSL=False
MAIL_USERNAME=username#gmail.com
MAIL_PASSWORD=app-specific-password
Any help or thoughts or tests for me to run would be greatly appreciated!
It turns out that by using a .env file that Flask was able to read automatically, was not passed into the context of the Gunicorn runner.
As per the answer linked belo, I have created this file which guarantees that both my .flaskenv and .env load no matter the context.
Running flask app with gunicorn and environment variables
# gunicorn.conf.py
import os
from dotenv import load_dotenv
for env_file in ('.env', '.flaskenv'):
env = os.path.join(os.getcwd(), env_file)
if os.path.exists(env):
load_dotenv(env)

gitpython: How to authenticate as a Github app?

When I do
remote = f"https://{username}:{password}#github.com/user/repo"
git.Repo.clone_from(remote, 'repo')
I get to clone the repository with my personal credentials.
But if I try an app credentials
remote = f"https://x-access-token:{token}#github.com/user/repo.git"
git.Repo.clone_from(remote, 'repo')
I get
remote: Invalid username or password. fatal: Authentication failed for
'https://github.com/user/repo'
I have installed the app and added it to the repository integrations. It has content permissions to read and write.
I am using the client secret as the token.

git submodule update via ssh error

I cloned the application commcare-hq after installing python and django in my cpanel. here's the link: https://github.com/dimagi/commcare-hq but whenever i enter the following command
git submodule update --init --recursive
i get the following error
fatal: clone of 'git://github.com/dimagi/xml2json.git' into submodule path
'/home/hcdcnetl/myProject/commcare-hq/submodules/xml2json' failed
Failed to clone 'submodules/xml2json'. Retry scheduled
Cloning into '/home/hcdcnetl/myProject/commcare-
hq/corehq/apps/hqmedia/static/hqmedia/MediaUploader'...
fatal: unable to connect to github.com:
github.com[0: 192.30.253.113]: errno=Connection refused
github.com[1: 192.30.253.112]: errno=Connection refused
git://github.com is not an SSH URL, it is a Git-protocol URL.
Try
git config --global url."git#github.com/".insteadOf git://github.com/
Any git://github.com/ will be replaced by the SSH URL git#github.com/...

django ldap auth not working from the app

anyone using django_auth_ldap against an active directory server
I am trying to set up auth through django_auth_ldap and am having an issue.
if i run my auth from the django interactive shell the auth works fine.
example from the shell
>>> from django.contrib.auth import authenticate
>>> authenticate(username='#############',password='*************')
search_s('ou=People, o=hp.com', 2, '(uid=%(user)s)') returned 1 objects: uid=###########,ou=people,o=hp.com
Populating Django ###########
Django user ########## does not have a profile to populate
<User:########## >
but the same code from within a view in the app fails with
Caught LDAPError while authenticating ##########: SERVER_DOWN({'desc': "Can't contact LDAP server"},)
I figured it out. I decided I would set up remote debugging so that I could step through the process and see where it was failing in that process I found that the httpd process was being prevented (by selinux) from making a network connection back to my eclipse IDE fixing this fixed the app. I think selinux was preventing the app from connecting to the ldap server. When I got my debug environment all worked out and stepped through it all worked fine !
the command to allow httpd to make a network connection
as root
setsebool -P httpd_can_network_connect 1

Heroku Neo4j Issue

I have my neo4j python application using py2neo.
It is working corretly on local but when i deploy it to heroku it is giving error
py2neo.rest.SocketError
SocketError: gaierror(-2, 'Name or service not known')
I am not sure what is the issue.
what should be the correct issue I am using url for db service as
graph_db = neo4j.GraphDatabaseService("http://xyz.hosted.neo4j.org:7480/db/data/")
Configure the authentication as indicated here:
http://packages.python.org/py2neo/neo4j.html#authentication
Use heroku config to note the username and password in the URL.
For example (obviously modified):
$ heroku config
=== secure-caverns-9214 Config Vars
NEO4J_URL: http://username:password#17d0afad4.hosted.neo4j.org:7755
PATH: bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin

Categories