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)