Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Python code for BitBucket repo invitations stopped working

NVIDIA DLI June 27, 2019

This script has been unchanged for a few years, and while sometimes I get similar errors, moving files around my machine and playing with directories somehow solves. Script:

#python invite_DL.py {bitbucket username} {bitbucket password} {file with email address on each line}

import json
import urllib
import urllib.request as urllib2
import sys
import base64

url = "https://api.bitbucket.org/1.0/invitations/junbo_jake_zhao/deeplearningkit/"

username = sys.argv[1]
password = sys.argv[2]
filename = sys.argv[3]
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, username, password)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
urllib.request.install_opener(opener)

with open(filename) as f:
for email in f:
data = urllib.parse.urlencode({"permission": "read"})
req = urllib2.Request(url + email.replace("\n",""), data.encode('ascii'))
base64string = base64.b64encode(bytes('%s:%s' % (username, password),'ascii'))
req.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))
f = urllib2.urlopen(req)
response = f.read()
print(response)
f.close()

 

When running this now I get the following. Sometimes it's 401: Unathorized error as well. Any ideas?

 

Traceback (most recent call last):
File "C:\BB_Invites\invite_DL.py", line 27, in <module>
f = urllib2.urlopen(req)
File "C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 471, in open
response = meth(req, response)
File "C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 581, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 509, in error
return self._call_chain(*args)
File "C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 589, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

 

I also tried using account id instead of username/email  but get exact same error, it's not even getting to my Bitbucket login apparently. Here is the command:


C:\Users\jbungo\AppData\Local\Programs\Python\Python35-32\python C:\BB_Invites\invite_DL.py [username/user id] [password] C:\BB_Invites\BB_Emails_DL.txt


I saw some changes related to gpdr went into effect in April, but just last week this script was working fine. I bump into issues like this every so often, then move files around my machine until it works without changing the script, but that's not working this time.

I also thought I had to be logged into Bitbucket on my machine but that doesn't seem to matter right now.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events