You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
anoduck
3 years agoExplorer | Level 4
`BadInputError: "No auth function for given request"` ...but I did.... So, what is happening?
It was working when I used the straight access token, but having to approve a new token every time the script was run was infeasible and irritating. So, I have migrated over to using a refresh_token, which has been successfully acquired and saved. Now I am attempting to test uploading file contents to a designated file in the box of drop-ness.
Traceback (most recent call last):
File "/home/vassilios/Sandbox/orgzly-y-py/main.py", line 480, in <module>
main()
File "/home/vassilios/Sandbox/orgzly-y-py/main.py", line 471, in main
dropbox_put(config['app_key'], config['dropbox_folder'],
File "/home/vassilios/Sandbox/orgzly-y-py/main.py", line 389, in dropbox_put
dropbox_upload(app_key, fullname, folder, name)
File "/home/vassilios/Sandbox/orgzly-y-py/main.py", line 298, in dropbox_upload
res = dbx.files_upload(
File "/usr/local/lib/python3.9/site-packages/dropbox/base.py", line 3207, in files_upload
r = self.request(
File "/usr/local/lib/python3.9/site-packages/dropbox/dropbox_client.py", line 301, in request
self.check_and_refresh_access_token()
File "/usr/local/lib/python3.9/site-packages/dropbox/dropbox_client.py", line 369, in check_and_refresh_access_token
self.refresh_access_token(scope=self._scope)
File "/usr/local/lib/python3.9/site-packages/dropbox/dropbox_client.py", line 403, in refresh_access_token
self.raise_dropbox_error_for_resp(res)
File "/usr/local/lib/python3.9/site-packages/dropbox/dropbox_client.py", line 627, in raise_dropbox_error_for_resp
raise BadInputError(request_id, res.text)
dropbox.exceptions.BadInputError: BadInputError('ba53047e1ac14efd97fac1e6ceea178f', '{"error": "invalid_request", "error_description": "No auth function available for given request"}')
The block of code generating the error should look very familiar to everyone, it is a stripped down and modified revision of the upload function from `updown.py` in the Dropbox repo. The biggest change in the function is removal of the unneeded call to `stopwatch`, and the addition of a request for new access token, which I "borrowed" from this forum. It is straight forward, which is why I am surprised to have received the error.
So here it is:
def dropbox_upload(app_key, fullname, folder, name, overwrite=False):
"""Upload a file.
Return the request response, or None in case of error.
"""
config = ConfigObj(DBX_CONFIG_FILE)
REFRESH_TOKEN = config['dropbox_token']
with dropbox.Dropbox(
oauth2_refresh_token=REFRESH_TOKEN, app_key=app_key) as dbx:
path = '/%s/%s' % (folder, name)
while '//' in path:
path = path.replace('//', '/')
mode = (dropbox.files.WriteMode.overwrite
if overwrite
else dropbox.files.WriteMode.add)
mtime = os.path.getmtime(fullname)
client_modified = datetime.datetime(*time.gmtime(mtime)[:6])
with open(fullname, 'rb') as f:
data = f.read()
try:
res = dbx.files_upload(
data, path, mode, client_modified=client_modified, mute=True)
except exceptions.ApiError as err:
print('*** API error', err)
return None
print('uploaded as', res.name.encode('utf8'))
return res
I have searched through the OAuth guide and the Python SDK for references to this error, and did not find anything. So, why is this not working?
(corrected formatting 10-17 3:00pm)
anoduck In addition to Здравко's note, make sure you're supplying all of the necessary credentials. I see you're currently setting a refresh token and app key. That would be sufficient if that refresh token was retrieved using PKCE, in which case the app secret isn't used. If PKCE wasn't used to retrieve that app key though, you need to set app_secret in addition to the app key and refresh token.
- Greg-DBDropbox Staff
anoduck In addition to Здравко's note, make sure you're supplying all of the necessary credentials. I see you're currently setting a refresh token and app key. That would be sufficient if that refresh token was retrieved using PKCE, in which case the app secret isn't used. If PKCE wasn't used to retrieve that app key though, you need to set app_secret in addition to the app key and refresh token.
- anoduckExplorer | Level 4
That was it, needed to add the app_secret along with the app_key and refresh token in order to get proper authentication. Now, just working to clear up some file conflict errors.
UploadError('path', UploadWriteFailed(reason=WriteError('conflict', WriteConflictError('file', None))
Will have to do after taking care of puppy dog.
AND, Done.
- ЗдравкоLegendary | Level 20
Hi anoduck,
One thing you can check is the correctness of you REFRESH_TOKEN. Print it out and check the value for proper formatting. There might be something different than the refresh token exactly or some additional symbols can appear (like extra quotes for instance).
Good luck.
- anoduckExplorer | Level 4
This was my first thought on the matter as well, that maybe it is being passed as a string rather than as raw input, or perhaps it should be passed as string and not raw input, but the addition of a "str(...)" made no difference in the output.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 5 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!