cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error 400 using download link from embedded code

Error 400 using download link from embedded code

terryz
Explorer | Level 3

I have an embedded piece of code that once upon a time worked before TLS v1 was deprecated.  Note the URL download link in the subject line above was modified to protect the file.  The unmodified link works fine with Chrome and Edge as the client.  I have been trying to modify the code in my embedded application to use TLS v1.2 to make it work again.   Below is the code snippet that I am trying to modify.  I am guessing my header {} settings are incorrect.  Below the code is the html response I get back from Dropbox - basically error 400.   Do I need to create my own agent to do this or did I not put in the correct header {} information?  I am using the typical Edge and Chrome header for 'Agent'...

 

Code:

local https = require("ssl.https")
        local ltn12 = require("ltn12")
        local options = {}
        local fileMode = isbinary and "wb" or "w"

        f = io.open(fulllocalpath, fileMode)
        if not f then
            resultstr = "Failed to open local file for writing:" .. fulllocalpath .."\r"
            return false, nil, nil, resultstr
        end

        options = {
            url = rawname,
            sink = ltn12.sink.file(f),
            protocol = "tlsv1_2",
            headers = {    --IS THERE SOMETHING WRONG HERE???
                ["Host"] = "www.dropbox.com",
                ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",
                ["Accept"] = "*/*",
                ["Referer"] = "https://www.dropbox.com/",
                ["Accept-Encoding"] = "gzip, deflate, br",
                ["Connection"] = "keep-alive"
            }
        }
 
Here is the html response back from Dropbox:
<.DOCTYPE html> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Dropbox - 400</title> <link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/error.css" rel="stylesheet" type="text/css"/> <link rel="shortcut icon" href="https://cfl.dropboxstatic.com/static/images/favicon.ico"/> </head> <body> <div class="figure"> <img src="https://assets.dropbox.com/www/en-us/illustrations/spot/target-miss.svg" alt="Error: 400"/> </div> <div id="errorbox"> <h1>Error (400)</h1>Something went wrong. Don't worry, your files are still safe and the Dropbox team has been notified. Check out our <a href="https://status.dropbox.com">Status Page</a> to see if there is a known incident, our <a href="https://www.dropbox.com/help">Help Center</a> and <a href="https://forums.dropbox.com">forums</a> for help, or head back to <a href="https://www.dropbox.com/home">home</a>. </div> </body> </html>
 
32 Replies 32

terryz
Explorer | Level 3

Hi - I do take out the '#' on the redirect link.

It is now working with the 'standard' link, however I am still getting a 400 error when I use the standard link https://www.dropbox.com/s/gxxxxxxxxblablahfile.TXT?dl=1.  This returns error 400. 

So I modified the code to ignore this error 400 and look for the redirect URL anyway, which is provided, despite getting the 400 from dropbox.com.

 

The code then strips off the trailing '#' character, and reissues new http request with the redirect link.  The file is downloaded successfully, and the return code is now 200 - indicating success, which it is!

 

So...why am I getting a 400 error on the first http request with the standard link, but I still get a redirect URL to the file anyway, and then making the exact same http request except modifying the url to the redirect link, then get the file downloaded and code 200?

 

Here is my header setup - what is wrong with it causing the initial error 400?


            resp, resultcode, respheaders, respstatus  =  https.request{
                url = rawname,
                sink = ltn12.sink.file(io.open(fulllocalpath, "wb")),
                protocol = "tlsv1_2",
                verify = "none",
                options = "all",
                --method = "GET",
                headers = {
                    ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
                    ["Accept"] = "*/*",
                    ["Connection"] = "keep-alive"
                }
            }

terryz
Explorer | Level 3

Here is my log showing what is going on, getting the inital 400 error, but still getting the file.  You can see the inital error 400 received, followed by the header received back which includes the redirect URL.  Followed by a call back to the redirect URL and showing file downloaded successfully (The file is indeed downloaded correctly).


Downloading text file: commands.UpdateControllerConfigFile
Starting download to local directory: cfgNfw/TEST7.CSV
Download From: https://www.dropbox.com/s/y5jlwu5nfr3s8xe/FAULTMSG.CSV?dl=1
File download resultcode [400].
headers: x-dropbox-response-origin:local
headers: content-type:text/html
headers: location:https://ucaa969fc16fd56378489df5cb52.dl.dropboxusercontent.com/cd/0/get/B-0OSKvdAZc91gDuj8YBWre69-Dx...
headers: vary:Accept-Encoding
headers: content-length:1005
headers: connection:close
headers: date:Wed, 28 Jun 2023 13:22:17 GMT
headers: server:envoy
Redirecting to: [https://ucaa969fc16fd56378489df5cb52.dl.dropboxusercontent.com/cd/0/get/B-0OSKvdAZc91gDuj8YBWre69-Dx...].
Redirect Count: 1.
File download resultcode [200].
File Downloaded Successfully
Successfully downloaded file: TEST7.CSV to gateway.

 

Greg-DB
Dropbox Staff

@terryz I'm glad to hear you got this working!

 

When starting from a /s/...?dl=1 link, there may be multiple redirects that need to be followed, which the client would handle do by issuing multiple requests. A 400 error response indicates that that particular request (that is, the one to which the response is sent) was invalid in some way. For instance, clients are automatically supposed to not include the fragment, but it sounds like you were able to work around that issue.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    terryz Explorer | Level 3
What do Dropbox user levels mean?