3

I have a python script ( I know only basics of Python ) which checks out multiple git projects in a loop. I can specify user name and password in Python script as specified in - How to Git Username and password

but I have a kind of organizational rule that password must have '@' character so git starts interpreting password part ( after @ ) as part of URL due to presence of @. Python string is as - "https://user:pass1@pass2@GIT_SERVER_URL"+ '/'+ self.project_group + '/' + self.name + '.git'

Is there a way to fix this?

git gives error that URL can't be resolved due to presence of @ in password.

I can checkout projects manually by entering passwords on command prompt for each project but requirement is to do it fully automated way. I am using Windows 8.1 and Python 2.7.10.

Community
  • 1
  • 1
Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
  • Why not use SSH link when cloning rather than https link? – TheGeorgeous Oct 20 '15 at 06:10
  • @TheGeorgeous : There are two reasons, 1. I just thought that it would be easy to move script around on various user machines as they can easily replace their credentials ( than generating and copying SSH keys for each machine ). 2. Windows login user is different than git user – Sabir Khan Oct 20 '15 at 06:19
  • The title conflicts with your question (you use an SSH remote in the title, but a HTTPS url in the question). Also RE your reasons: 1) Especially for automated stuff, SSH keys are a lot more secure since they don’t store the password in plain text inside that script. It also avoids having to reconfigure it with password changes or for new users. Users are just required to set up an SSH key and register it with the server, and the script will work for all of them automatically. 2) That’s no problem at all. SSH keys use a separate authentication mechanism anyway. – poke Oct 20 '15 at 06:50
  • Sorry for the title, I have corrected it. I will see if SSH can be used, many thanks. – Sabir Khan Oct 20 '15 at 07:38

1 Answers1

6

You can use the URL encoded value for @ : %40

Something like:

"https://user:pass1%40pass2@GIT_SERVER_URL"+ '/'+ self.project_group + '/' + self.name + '.git'
arodriguezdonaire
  • 5,396
  • 1
  • 26
  • 50