2

I have this small code in a python lambda that is trying to pull down a repo from bitbucket:

import git

def git_clone(username,password):
   new_dir = os.getcwd() + "/temp/"
   os.chdir(new_dir)

   GIT_URL = "https://{0}:{1}@bitbucket.org/test-project/test.git".format(username,password)

   git.Git(new_dir).clone(GIT_URL)

The git method accepts my username but does not accept my password. My password contains letters, numbers and special chars. i get this error:

URL using bad/illegal format or missing URL

Could this be a formatting issue?

5
  • try making it a raw string r" Commented Nov 18, 2021 at 15:56
  • 2
    Special characters in password must be URL-encoded. Commented Nov 18, 2021 at 15:56
  • 1
    i've tried r" . still no luck @rv.kvetch Commented Nov 18, 2021 at 16:17
  • 1
    how do i do that? @phd Commented Nov 18, 2021 at 16:17
  • Don't put the credentials in the URL, since that means they get written to disk. Use a credential helper. Commented Nov 18, 2021 at 22:24

1 Answer 1

1

See the documnetation if using bitbucket

git clone "https://x-token-auth:{token}@bitbucket.org/<user_name>/"

or

url = r"https://x-token-auth:{token}@bitbucket.org/<user_name>/"

git clone url

Here is a solution to your problem. I tested it and it works.

#!/usr/bin/env python
import os 

def git_clone(password, username):
    if password and username:
        url_string = r"git clone https://{}:{}@bitbucket.org/{}/test.git".format(username, password, username)
        os.system(url_string)
git_clone(username="<username>", password="<password>")

If this solves your problem, don't forget to accept and upvote it as the correct answer

Sign up to request clarification or add additional context in comments.

2 Comments

But im using bitcbucket?
I modified my answer, please see above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.