<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python API: dbx.files_upload does not upload files sometimes (no errors reported) in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748267#M32868</link>
    <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1799496"&gt;@Egorov_WIIW&lt;/a&gt; Like Здравко said, make sure you're catching and handling any/all potentially relevant exceptions. Additionally, for the case where no exceptions are being raised, check the return value of files_upload.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2024 16:17:17 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2024-01-31T16:17:17Z</dc:date>
    <item>
      <title>Python API: dbx.files_upload does not upload files sometimes (no errors reported)</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748219#M32863</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;We are setting up a process with daily upload of the CSV files from the local repository to the Dropbox repo. The dropbox folder belongs to another colleague with a different Dropbox account, but it is a shared one with a turned-on right to edit and overwrite files.&lt;BR /&gt;Retrieval of the access token works fine, downloading files from Dropbox works too.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;However, the functions that upload documents to the folder work inconsistently.&lt;BR /&gt;The script runs without throwing any error messages. However, sometimes the files do not appear in the Dropbox folder (or only some of them appear).&lt;BR /&gt;&lt;BR /&gt;Here are 2 functions we are using for uploads, both of them work and do not work from time to time without any clear pattern:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def upload_to_dropbox(access_token, project_folder, folder):
    dbx = dropbox.Dropbox(access_token)

    try:
        files_to_upload = define_upload_files()

        for file in files_to_upload:
            local_file_path = os.path.join(folder, file)
            dropbox_path = f'/{project_folder}/{folder}/{file}'.replace(os.path.sep, '/')

            with open(local_file_path, 'rb') as f:
                file_content = f.read()
                dbx.files_upload(file_content, dropbox_path, mode = dropbox.files.WriteMode('overwrite'))
                print(f"File uploaded to Dropbox: {dropbox_path}")

    except ApiError as e:
        print(f"Error: {e}")

def upload_csvs(access_token, project_folder, folder):
    dbx = dropbox.Dropbox(access_token)
    try:
        files_to_upload = define_upload_files()
        for file in files_to_upload:
            local_file_path = os.path.join(folder, file)
            df = pd.read_csv(local_file_path)
            csv_content = df.to_csv(index=False)
            dropbox_path = f'/{project_folder}/{folder}/{file}'.replace(os.path.sep, '/')
            dbx.files_upload(csv_content.encode('utf-8'), dropbox_path, mode=dropbox.files.WriteMode('overwrite'))
            print(f"CSV uploaded to Dropbox: {dropbox_path}")
    except dropbox.exceptions.ApiError as e:
        print(f"Error uploading CSV file to Dropbox: {e}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 13:39:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748219#M32863</guid>
      <dc:creator>Egorov_WIIW</dc:creator>
      <dc:date>2024-01-31T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: dbx.files_upload does not upload files sometimes (no errors reported)</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748228#M32865</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1799496"&gt;@Egorov_WIIW&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;There are variety of reasons for such behavior. You didn't check actually for all possible cases! Try catch 'DropboxException' in an except statement, not only 'ApiError'. There should be some more information. By the way using access token only is not a good idea. It expires and you need to authorize your application anew. Share single Dropbox client object instead of access token. Once properly initialized with refresh token such an object will work in a more stable way and more efficiently. &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt;&lt;/P&gt;&lt;P&gt;Hope this gives direction.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 14:20:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748228#M32865</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2024-01-31T14:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: dbx.files_upload does not upload files sometimes (no errors reported)</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748267#M32868</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1799496"&gt;@Egorov_WIIW&lt;/a&gt; Like Здравко said, make sure you're catching and handling any/all potentially relevant exceptions. Additionally, for the case where no exceptions are being raised, check the return value of files_upload.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 16:17:17 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Python-API-dbx-files-upload-does-not-upload-files-sometimes-no/m-p/748267#M32868</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2024-01-31T16:17:17Z</dc:date>
    </item>
  </channel>
</rss>

