<?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: AssertionError: Expected content-type to be application/json, got 'application/grpc' in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765624#M33484</link>
    <description>&lt;P&gt;Thanks for following up. The API functionality you're attempting to use is available to all Dropbox plans/trials, and even if an API error is returned, it shouldn't be sent with that Content-Type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's unclear what would be causing this, so we'll need to look into this further. Can you please try running the following at least 5 times and send me the output? This will enable more verbose output which may be helpful for investigating this issue:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import http.client
http.client.HTTPConnection.debuglevel = 1

import dropbox
dbx = dropbox.Dropbox('ACCESS_TOKEN_HERE')
print(dbx.users_get_current_account())&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to replace ACCESS_TOKEN_HERE with the access token you're using. As long as that access token starts with "sl." and it has been more than four hours since the access token has been created, please leave it in the output as it would be expired anyway and may be helpful for investigating this.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2024 18:50:16 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2024-04-22T18:50:16Z</dc:date>
    <item>
      <title>AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/764861#M33455</link>
      <description>&lt;P&gt;Hi, everybody!&lt;BR /&gt;&lt;BR /&gt;I have a simple Python script to create an archive and store it in Dropbox.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import subprocess
import os
import dropbox
import shutil
from datetime import datetime

class DropboxUploader:
    def __init__(self, dropbox_token, CHUNK_SIZE):
        self.dropbox_token = dropbox_token
        self.CHUNK_SIZE = CHUNK_SIZE
        self.dbx = dropbox.Dropbox(dropbox_token)

    def upload(self, file_name, file_size):
        with open(f"{pwd}/{file_name}", 'rb') as f:
            upload_session_start_result = self.dbx.files_upload_session_start(f.read(self.CHUNK_SIZE))
            cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id, offset=f.tell())
            commit = dropbox.files.CommitInfo(path=f"{pwd}/{file_name}")

            while f.tell() &amp;lt; file_size:
                if ((file_size - f.tell()) &amp;lt;= self.CHUNK_SIZE):
                    self.dbx.files_upload_session_finish(f.read(self.CHUNK_SIZE), cursor, commit)
                else:
                    self.dbx.files_upload_session_append_v2(f.read(self.CHUNK_SIZE), cursor.session_id, cursor.offset)
                    cursor.offset = f.tell()

#Change those variables 
root_dir = '/home/user/site_name'
site = 'site'
database = 'database'
dropbox_token = 'xxxxxxxxxxxxxxx'

CHUNK_SIZE = 8 * 1024 * 1024  # 8MB
archive_name = site + '_' + datetime.now().strftime("%Y%m%d_%H%M%S")
database_dump_name = database + '_' + datetime.now().strftime("%Y%m%d_%H%M%S") + '.sql'
pwd = os.getcwd()

archive_path = shutil.make_archive(archive_name, 'tar', root_dir)
archive_name = os.path.basename(archive_path)

command = f"mysqldump -u root {database} &amp;gt; {database_dump_name}"
subprocess.run(command, shell=True)

archive_size = os.path.getsize(f"./{archive_name}")
database_dump_size = os.path.getsize(f"./{database_dump_name}")

# Only for file sizes less than 150 MB 
# dbx = dropbox.Dropbox(dropbox_token)
# with open(f"./{archive_name}.tar", 'rb') as f:
#     dbx.files_upload(f.read(), f"{pwd}/{archive_name}.tar")
# with open(f"./{database_dump_name}.sql", 'rb') as f:
#     dbx.files_upload(f.read(), f"{pwd}/{database_dump_name}.sql")

uploader = DropboxUploader(dropbox_token, CHUNK_SIZE)
uploader.upload(archive_name, archive_size)
uploader.upload(database_dump_name, database_dump_size)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;But there is an error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Exception has occurred: AssertionError
Expected content-type to be application/json, got 'application/grpc'
  File "/home/user/dropbox/dropbox_backup.py", line 15, in upload
    upload_session_start_result = self.dbx.files_upload_session_start(f.read(self.CHUNK_SIZE))
  File "/home/user/dropbox/dropbox_backup.py", line 54, in &amp;lt;module&amp;gt;
    uploader.upload(archive_name, archive_size)
AssertionError: Expected content-type to be application/json, got 'application/grpc'&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;I saw this post&amp;nbsp;&lt;A href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/python-upload-big-file-example/td-p/166626" target="_blank" rel="noopener"&gt;Python upload big file example - Dropbox Community (dropboxforum.com)&lt;/A&gt;&amp;nbsp;my code is practically the same, and I don't get why mine isn't working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 07:09:10 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/764861#M33455</guid>
      <dc:creator>homopoluza</dc:creator>
      <dc:date>2024-04-22T07:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/764917#M33461</link>
      <description>&lt;P&gt;Thanks for the report! This error indicates that the Dropbox API servers did not respond with the expected format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just tried this out myself though, and I wasn't able to reproduce this. This kind of issue could just be a result of temporary server issues. Are you still seeing this problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are still seeing this, please let me know:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;about what percent of your calls fail like this&lt;/LI&gt;
&lt;LI&gt;if this code was previously working for you, and if so, when you saw this problem start occurring&lt;/LI&gt;
&lt;LI&gt;whether or not other calls, such as `self.dbx.users_get_current_account()` also fail like this for you&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 18 Apr 2024 17:00:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/764917#M33461</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2024-04-18T17:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765426#M33477</link>
      <description>&lt;P&gt;Sorry for the late reply.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;about what percent of your calls fail like this&lt;BR /&gt;All of them&lt;/LI&gt;&lt;/UL&gt;&lt;UL&gt;&lt;LI&gt;if this code was previously working for you, and if so, when you saw this problem start occurring&lt;BR /&gt;No, this is a new script for me, I wrote it with the help of this post&lt;BR /&gt;&amp;nbsp;&lt;A href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/python-upload-big-file-example/td-p/166626" target="_blank" rel="noopener"&gt;https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/python-upload-big-file-example/td-p/166626&lt;/A&gt;&lt;BR /&gt;It worked for others without problems.&lt;/LI&gt;&lt;LI&gt;whether or not other calls, such as `self.dbx.users_get_current_account()` also fail like this for you&lt;BR /&gt;Unfortunately yes. The token was provided to me by my colleague. Could it be restrictions of trial account perhaps?&lt;BR /&gt;&lt;SPAN&gt;print(dbx.users_get_current_account()) &lt;/SPAN&gt;&lt;SPAN&gt;AssertionError: Expected content-type to be application/json, got 'application/grpc'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for your assistance&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 22 Apr 2024 06:04:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765426#M33477</guid>
      <dc:creator>homopoluza</dc:creator>
      <dc:date>2024-04-22T06:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765624#M33484</link>
      <description>&lt;P&gt;Thanks for following up. The API functionality you're attempting to use is available to all Dropbox plans/trials, and even if an API error is returned, it shouldn't be sent with that Content-Type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's unclear what would be causing this, so we'll need to look into this further. Can you please try running the following at least 5 times and send me the output? This will enable more verbose output which may be helpful for investigating this issue:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import http.client
http.client.HTTPConnection.debuglevel = 1

import dropbox
dbx = dropbox.Dropbox('ACCESS_TOKEN_HERE')
print(dbx.users_get_current_account())&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to replace ACCESS_TOKEN_HERE with the access token you're using. As long as that access token starts with "sl." and it has been more than four hours since the access token has been created, please leave it in the output as it would be expired anyway and may be helpful for investigating this.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 18:50:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765624#M33484</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2024-04-22T18:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765758#M33488</link>
      <description>&lt;P&gt;after multiple times&lt;BR /&gt;&lt;BR /&gt;the output&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;bazhin@DESKTOP-2IOFFID:~/dropbox$  /usr/bin/env /bin/python3 /home/bazhin/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher 42309 -- /home/bazhin/dropbox/test2.py 
send: b'POST /2/users/get_current_account HTTP/1.1\r\nHost: api.dropboxapi.com\r\nUser-Agent: OfficialDropboxPythonSDKv2/11.36.2\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Bearer sl.BznBUIsodC4OmcMX9vn7wX6TOTMiFbTfTF7preTpNpCWTwG_hwF3p30YXdak\xadKcgIDP5CggtIwJ1ScpQWlPNfVggJQLY2uIEPAQdLTFyVvsSnF_mIN8Ji52N1\xadXkQljr3_5RiJPNPVFEwq\r\nContent-Type: application/json\r\nContent-Length: 4\r\n\r\n'
send: b'null'
reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Content-Type: application/grpc
header: Date: Tue, 23 Apr 2024 05:59:06 GMT
header: Server: envoy
header: Content-Length: 0
header: X-Dropbox-Response-Origin: far_remote
header: X-Dropbox-Request-Id: 05ae29d6341d48268d19838cbfda16d5&lt;/LI-CODE&gt;&lt;P&gt;the error&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Exception has occurred: AssertionError
Expected content-type to be application/json, got 'application/grpc'
  File "/home/bazhin/dropbox/test2.py", line 6, in &amp;lt;module&amp;gt;
    print(dbx.users_get_current_account())
AssertionError: Expected content-type to be application/json, got 'application/grpc'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 06:27:26 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765758#M33488</guid>
      <dc:creator>homopoluza</dc:creator>
      <dc:date>2024-04-23T06:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765768#M33490</link>
      <description>&lt;P&gt;Well, I decided to create my own app for testing on my own current account.&lt;/P&gt;&lt;DIV class=""&gt;Permission type -&amp;nbsp;&lt;SPAN&gt;account_info.read -&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Scoped App&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;And&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;print(dbx.users_get_current_account())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;works just fine now.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Then I added&amp;nbsp;&lt;SPAN&gt;files.content.write permission and tried my script from the first post and got&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Exception has occurred: AuthError
AuthError('1c1aa051ebc4408297c28154348ecaf8', AuthError('missing_scope', TokenScopeError(required_scope='files.content.write')))
  File "/home/bazhin/dropbox/dropbox_backup.py", line 15, in upload
    upload_session_start_result = self.dbx.files_upload_session_start(f.read(self.CHUNK_SIZE))
  File "/home/bazhin/dropbox/dropbox_backup.py", line 54, in &amp;lt;module&amp;gt;
    uploader.upload(archive_name, archive_size)
dropbox.exceptions.AuthError: AuthError('1c1aa051ebc4408297c28154348ecaf8', AuthError('missing_scope', TokenScopeError(required_scope='files.content.write')))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I guess I have to wait for permission update or something, haven't I?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 07:02:05 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765768#M33490</guid>
      <dc:creator>homopoluza</dc:creator>
      <dc:date>2024-04-23T07:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: AssertionError: Expected content-type to be application/json, got 'application/grpc'</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765794#M33491</link>
      <description>&lt;P&gt;I just renewed the token, and all is good. Thank you for your time Greg-DB&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 09:30:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/AssertionError-Expected-content-type-to-be-application-json-got/m-p/765794#M33491</guid>
      <dc:creator>homopoluza</dc:creator>
      <dc:date>2024-04-23T09:30:40Z</dc:date>
    </item>
  </channel>
</rss>

