cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The given OAuth 2 access token is malformed.

The given OAuth 2 access token is malformed.

hrh747
Helpful | Level 5
Go to solution

Hi,

 

Previously, I had saved the OAuth 2 access token in a variable in my Python code, and I was able to use the token to connect and download files from my Dropbox folders. However, I decided to store the OAuth 2 access token in a local file on my drive instead, so in case (for some inexplicable reason) if it changed in the future, I wouldn't have to make any code change. Unfortunately, under this scenario I get the following error when I try to download files:

 

 File "C:\Users\lib\site-packages\dropbox\base.py", line 1310, in files_download_to_file
r = self.request(
File "C:\Users\hrh74\lib\site-packages\dropbox\dropbox_client.py", line 323, in request
res = self.request_json_string_with_retry(host,
File "C:\Users\lib\site-packages\dropbox\dropbox_client.py", line 479, in request_json_string_with_retry
return self.request_json_string(host,
File "C:\Users\lib\site-packages\dropbox\dropbox_client.py", line 604, in request_json_string
raise BadInputError(request_id, r.text)
dropbox.exceptions.BadInputError: BadInputError('5a7e90464ddc473e925b048f9a99fc08', 'Error in call to API function "files/download": The given OAuth 2 access token is malformed.')
 

The file that has the OAuth 2 token is a simple text file with one line with the token as follow:

"xyz........"

 

Any insight as why the token within the code works but retrieving it from a local text file doesn't?

 

Thanks in advance

1 Accepted Solution

Accepted Solutions

Здравко
Legendary | Level 20
Go to solution

Hi @hrh747,

Since you have your access token checked and it's working, seems you have saved the token in wrong way and/or improperly read it within your code. The best way for debug this case, I think, is to "resurrect" the variable you did use before, so there would be reference value. Compare value you are reading from file to the reference one. Does they match? 🤔 If need, compare the values symbol by symbol to find out where precisely the difference is. 😉 By the way, have you stripped blanks on read?

Hope this gives right direction.

View solution in original post

3 Replies 3

Здравко
Legendary | Level 20
Go to solution

Hi @hrh747,

Since you have your access token checked and it's working, seems you have saved the token in wrong way and/or improperly read it within your code. The best way for debug this case, I think, is to "resurrect" the variable you did use before, so there would be reference value. Compare value you are reading from file to the reference one. Does they match? 🤔 If need, compare the values symbol by symbol to find out where precisely the difference is. 😉 By the way, have you stripped blanks on read?

Hope this gives right direction.

hrh747
Helpful | Level 5
Go to solution

Hi there,

 

Thanks for the kind response. Yes, I have stripped the blank while reading the token, however, I am to take your advice and make the string comparison to see where the difference might be. I will let you know.

 

Thanks again.

hrh747
Helpful | Level 5
Go to solution

Thanks for the tip. The string comparison revealed an interesting fact. A pair of double quotes surrounded the token in the external file. It turned out that Python wrapped the token with additional pair of single quotes when reading it from the external file. I saved the token in the file without the double-quotes, and the code is working now 🙂

 

I thank you immensely for the help. 

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    hrh747 Helpful | Level 5
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?