0
votes

I am able to authenticate and connect to the DropBox API and run team-members-list.

But I get the following error when I attempt to run team-members-remove with additional header and data in the request.

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:

When adding try:

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Python code so far:

headers = {'Authorization': 'Bearer ' + TOKEN}
url = 'https://api.dropboxapi.com/2/team/members/remove'
data = {
    "user": {".tag": "team_member_id", "team_member_id": userid}, 
    "wipe_data": "true", 
    "transfer_dest_id": {".tag": "team_member_id", "team_member_id": adminid},
    "transfer_admin_id": {".tag": "team_member_id", "team_member_id": adminid},
    "keep_account": "false",
}
response = requests.post(url, data=data, headers=headers)

I have attempted some variations on the above, including:

headers = {'Authorization': 'Bearer ' + TOKEN, "Content-Type": "application/json" }
response = requests.post(url, json=data, headers=headers)
data = json.dump(data)

There are a few of these errors documented here, I've had a read of them and implemented the suggestions but still not been able to resolve this.

Any pointers greatly appreciated.

Background:

  • Python 3.5.2
  • Requests
  • Dropbox for Business API
1
@Tomalak thanks for formatting. Looks much better. Will submit this way going forward. - user45097
No problem. Can't help you with the question itself though, unfortunately. - Tomalak

1 Answers

0
votes

Where I was going wrong was I was attempting to run the response.text through json.loads e.g.

message = json.loads(response.text)

I changed this to

print(response.text)

This way I was presented with the helpful error messages.

Code now looks like this and its working:

headers = {"Authorization": "Bearer " + TOKEN, "Content-Type": "application/json"}
jsondata = json.dumps(data)
response = requests.post(url, data=jsondata, headers=headers)