-1

I have searched some code about bitbucket-api (here)

How to download "zip" by using Bitbucket-api and Python on Windows10 ?

I use :

Python 3.5.0

Bitbucket-api 0.5.0 (from pip install bitbucket-api )

Windows 10

-----update
Do I miss parameter in bb.repository.archive() ?

>>>from bitbucket.bitbucket import Bitbucket
>>>USERNAME = 'CCC'
>>>PASSWORD = 'BBB'    
>>>bb = Bitbucket(USERNAME, PASSWORD, repo_name_or_slug="Py-Bitbucket-api")
>>>success, result = bb.repository.get()
>>>print (bb.repository.get())
True{......}
>>>success, archive_path = bb.repository.archive()
>>> print (success, archive_path)
True C:\....\Temp\tmp_zxpa_14

It download some tmp files.(tmp_zxpa_14....)

But it not a zip .

Do I miss some parameter?

BTW

I wandt to download one of file in my repo.

Can Bitbucket-api specify the file to download? How to modify my code?

soysoy
  • 289
  • 2
  • 10

2 Answers2

0

use bitbucket-api only can deal with "https://bitbucket.org/account/signin/?next=/site/oauth1/authorize%3Foauth_token%3DNone" info? if i deploy a bitbucket server in local,has any way to deal with its repository?

use the code down:

bitbucketUrl="http://localhost:7990/"
# bitbucketUrl="http://bitbucket.rd.800best.com/projects/EXPRESS/repos/q9taobao/browse"
USERNAME=""
OAUTH_ACCESS_TOKEN=""
OAUTH_ACCESS_TOKEN_SECRET=""
CONSUMER_SECRET=""
CONSUMER_KEY=""
bb=Bitbucket(USERNAME)
if not OAUTH_ACCESS_TOKEN and not OAUTH_ACCESS_TOKEN_SECRET:
    bb.authorize(CONSUMER_KEY,CONSUMER_SECRET,"http://localhost:7990/")
    webbrowser.open(bb.url('AUTHENTICATE',token=bb.access_token))
    oahtu_verifier=raw_input('Enter Verifier from url [oauth_verifier]')
    bb.verify(oauth_verifier)
    OAUTH_ACCESS_TOKEN=bb.access_token
    OAUTH_ACCESS_TOKEN_SECRET=bb.OAUTH_ACCESS_TOKEN_SECRET
else:
    bb.authorize(CONSUMER_KEY,CONSUMER_SECRET,'http://localhost:7990/',OAUTH_ACCESS_TOKEN,OAUTH_ACCESS_TOKEN_SECRET)
it redirect to "https://bitbucket.org/account/signin/?next=/site/oauth1/authorize%3Foauth_token%3DNone"
ling jin
  • 1
  • 2
-1

you can do it like

# Access a public repository
bb = Bitbucket(USERNAME, repo_name_or_slug="public_repository")
# Access a private repository
bb = Bitbucket(USERNAME, PASSWORD, repo_name_or_slug="private_repository")

# Download a repository as an archive
success, archive_path = bb.repository.archive()

Let me know if you need any clarification.

Nitesh Verma
  • 2,460
  • 4
  • 20
  • 36
  • I update my code. Please help me find what's wrong with my code.Thanks! – soysoy Feb 17 '17 at 05:18
  • Apparently, the package is not working for me as well now. I'll see this in night and let you know. – Nitesh Verma Feb 17 '17 at 09:31
  • Hi, I think I success download the file , but it not "zip".(I update my code.) I read the repository.py the function `archive(self, repo_slug=None, format='zip', prefix=''):` format default 'zip' .Did I understand wrong? – soysoy Feb 18 '17 at 01:52
  • You understood it right. But `archive` is not working for me. I am getting `False,Couldn't archive your project`. – Nitesh Verma Feb 19 '17 at 04:39
  • I use another repo. It is not working either. Also getting `False,Couldn't archive your project`. – soysoy Feb 21 '17 at 08:41