I have a program in Python 3.9 which cleans data every morning, creates a final dataset, and then uses the dropbox api to create a shared link with settings (password) for the file, then email that link with the password to those who subscribe to my daily newsletter.
This setup works... but only some of the time. For many months it was completely reliable, but now the creating shared link settings break the whole program.
By some of the time, I mean that the program will work Monday, Tuesday, Wednesday, but break on Thursday.
Luckily, I do get a continuous error, but am writing this because I am unable to find a fix.
Code:
import dropbox
dailyfile_csv = "\Daily Data (2020-12-29 10.07 AM).csv"
dailyfile_dta = "\Daily Data (2020-12-29 10.07 AM).dta"
/Daily Lobbying Data (2020-12-29 10.07 AM).dta
dbx = dropbox.Dropbox(token)
user = dbx.users_get_current_account()
print("Dropbox Account Info: " + str(dbx.users_get_current_account()))
#Should have logged onto dropbox application.
#STEP: Creating randomly generated passwords for the data.
csvpass = str(randompassword())
print("CSV Password = " + csvpass)
dtapass = str(randompassword())
print("DTA Password = " + dtapass)
#Created randomly generated passwords for the data.
#These are link settings for the files which say that the file requires a password, and we set the password equal to the randomly generated passwords above.
link_settings_csv = dropbox.sharing.SharedLinkSettings(
requested_visibility = dropbox.sharing.RequestedVisibility.password,
link_password=csvpass)
#expires = datetime.datetime.now() + datetime.timedelta(days=7))
link_settings_dta = dropbox.sharing.SharedLinkSettings(
requested_visibility = dropbox.sharing.RequestedVisibility.password,
link_password=dtapass)
#expires = datetime.datetime.now() + datetime.timedelta(days=7))
#Setting link settings as requiring password.
time.sleep(15)
#STEP: VERY IMPORTANT. This creates a link for the huge data file either in csv or dta format to be sent in the daily emails.
csv_link = dbx.sharing_create_shared_link_with_settings(dailyfile_csv,settings=link_settings_csv).url
time.sleep(10)
print(csv_link)
time.sleep(7)
dta_link = dbx.sharing_create_shared_link_with_settings(dailyfile_dta,settings=link_settings_dta).url
time.sleep(10)
print(dta_link)
time.sleep(7)
print("Finished creating dropbox links.")
Error Code:
#This happens right after attempting to create the first shared link.
Traceback (most recent call last):
File "D:\Dropbox\Lobbyingdata.com\Lobbying Data\Daily_Data_Step_3_Dropboxing.py", line 102, in <module>
csv_link = dbx.sharing_create_shared_link_with_settings(dailyfile_csv,settings=link_settings_csv).url
File "C:\Users\syxsc\AppData\Roaming\Python\Python39\site-packages\dropbox\base.py", line 3969, in sharing_create_shared_link_with_settings
r = self.request(
File "C:\Users\syxsc\AppData\Roaming\Python\Python39\site-packages\dropbox\dropbox_client.py", line 338, in request
raise ApiError(res.request_id,
dropbox.exceptions.ApiError: ApiError('dd1470bb63b1468b977c6c3fdd30afdc', CreateSharedLinkWithSettingsError('path', LookupError('not_found', None)))